栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 2003 Hire and Fire

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 2003 Hire and Fire

#include<iostream>#include<map>#include<list>#include<string>using namespace std;struct Tman{    string name;    Tman *father;    list<Tman *> sons;};map<string, Tman *> hash;Tman *root;void print(long dep, Tman *now){    if(now == NULL) return;    for(long i = 1; i <= dep; ++i)        cout<<"+";    cout<<now->name<<endl;;    for(list<Tman *>::iterator j = now->sons.begin(); j != now->sons.end(); ++j)        print(dep + 1, *j);}void hires(string n1, string n2) {    Tman *boss = hash[n1];    Tman *employee = new Tman();    employee->name = n2;    employee->father = boss;    boss->sons.push_back(employee);    hash[n2] = employee;}void fire(string n1){    Tman *p = hash[n1];    hash.erase(n1);    while(p->sons.size() > 0)    {        p->name = p->sons.front()->name;        hash[p->name] = p;        p = p->sons.front();    }        p->father->sons.remove(p);    delete p;}void solve(){    string str1,str2;    long i;    cin>>str1;    root = new Tman();    hash[str1] = root;    root->name = str1;    while(cin>>str1)    {        if(str1 == "print")        { print(0,root); cout<<"------------------------------------------------------------"<<endl;        }        else if(str1 == "fire")        { cin>>str2; fire(str2);        }        else        { cin>>str2; cin>>str2; hires(str1, str2);        }    }}int main(){    solve();    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/374485.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号