Problem A: 大学的组织架构

来源:互联网 发布:迅雷cdn 知乎 编辑:程序博客网 时间:2024/05/17 20:30

Problem A: 大学的组织架构

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 499  Solved: 411
[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

append.cc,

#include <bits/stdc++.h>using namespace std;class Orgnization{public:    string orname;    string topname;    Orgnization(string orname,string topname):orname(orname),topname(topname){}    virtual void show()=0;};class College:public Orgnization{public:    College(string _orname,string _topname):Orgnization(_orname,_topname){}    void show(){cout<<"Dean of "<<orname<<" is "<<topname<<endl;}};class Department:public Orgnization{public:    Department(string _orname,string _topname):Orgnization(_orname,_topname){}    void show(){cout<<"Director of "<<orname<<" is "<<topname<<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;}

0 0