大学的组织架构

4 篇文章 0 订阅

Problem C: 大学的组织架构Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 1695 Solved: 1358
[Submit][Status]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
4
0
College of Information
Tom Zhang
1
Department of Software
Jack Li
0
College of Math
Mary Wang
1
Department of Computer
Fu Qi

Sample Output
Dean of College of Information is Tom Zhang
Director of Department of Software is Jack Li
Dean of College of Math is Mary Wang
Director of Department of Computer is Fu Qi
HINTAppend Codeappend.cc,

#include<istream>
#include<string>
#include <bits/stdc++.h>
using namespace std;
class Orgnization{
public:
    string Oname;
    string Pname;
    Orgnization(){}
//    Animal(string name_):name(name_){ }
    virtual void show(){ }
};
class College:public Orgnization
{
public:
    string Oname,Pname;
    College(string Oname_,string Pname_):Oname(Oname_),Pname(Pname_){ }
 
    void show(){ cout<<"Dean of "<<Oname<<" is "<<Pname<<endl;}
};
class Department:public Orgnization
{
public:
    string Oname,Pname;
    Department(string Oname_,string Pname_):Oname(Oname_),Pname(Pname_){ }
    void show(){ cout<<"Director of "<<Oname<<" is "<<Pname<<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;
}

有关于getline和cin.ignore()函数的讲解
https://blog.csdn.net/wxbmelisky/article/details/48596881
https://www.cnblogs.com/xiaofeiIDO/p/8574042.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值