Problem C: 大学的组织架构
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1259 Solved: 999
[ Submit][ Status][ Web Board]
Description
一个大学是由若干个学院、系组成的,每个学院、系有自己的名称和领导。定义Orgnization类,具有2个string属性,分别是一个组织的名称和其领导的名字;具有一个show方法,用于显示该组织的信息。
该类有2个子类:College、Department。其中College的show方法显示格式为:
Dean of $ is &
Department的show方法显示格式为:
Director of $ is &
上述格式中,$表示College或Department的名字,&是相应的领导的名字。
Input
输入多行。
第1行N表示一个大学的下属机构的个数。
之后有N组输入。每组输入有3行,第1行是0或1,0表示这是一个College,1表示这是一个Department。
第2行是College或Department的名字。
第3行是相应的领导名字。
Output
见样例。
Sample Input
40College of InformationTom Zhang1Department of SoftwareJack Li0College of MathMary Wang1Department of ComputerFu Qi
Sample Output
Dean of College of Information is Tom ZhangDirector of Department of Software is Jack LiDean of College of Math is Mary WangDirector of Department of Computer is Fu Qi
HINT
Append Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#include<iostream>
#include<iomanip>
#include <cstdio>
#include <vector>
using
namespace
std;
class
Orgnization
{
private
:
string name1,name2;
public
:
virtual
void
show(){}
string getn1(){
return
name1;
}
string getn2(){
return
name2;
}
};
class
College:
public
Orgnization
{
string name1,name2;
public
:
College(string a,string b):name1(a),name2(b){}
void
show(){cout<<
"Dean of "
<<name1<<
" is "
<<name2<<endl;}
};
class
Department:
public
Orgnization
{
string name3,name4;
public
:
Department(string a,string b):name3(a),name4(b){}
void
show(){cout<<
"Director of "
<<name3<<
" is "
<<name4<<endl;}
};
int
main()
{
vector<Orgnization*> university;
vector<Orgnization*>::iterator itr;
int
n, i, t;
string str1, str2;
cin>>n;
for
(i = 0; i < n; i++)
{
cin>>t;
cin.ignore();
getline(cin, str1);
getline(cin, str2);
if
(t == 0)
university.push_back(
new
College(str1, str2));
else
university.push_back(
new
Department(str1, str2));
}
for
(itr = university.begin(); itr != university.end(); itr++)
(*itr)->show();
return
0;
}
|