来源:自学PHP网 时间:2015-04-14 14:51 作者: 阅读:次
[导读] * * POJ_2003 cpp * * Created on: 2013年11月5日 * Author: Administrator * include iostream include cstdio include map inc...
/* * POJ_2003.cpp * * Created on: 2013年11月5日 * Author: Administrator */ #include <iostream> #include <cstdio> #include <map> #include <list> #include <string> using namespace std; struct Tman{ string name; Tman* f; list<Tman*> s; Tman(){ f = NULL; } }; map<string,Tman*> hash; Tman* root; void print(long dep,Tman* now){ if(now == NULL){ return ; } long i; for(i = 1 ; i <= dep ; ++i){ cout<<'+'; } cout<<now->name<<endl; for(list<Tman*>::iterator it = now->s.begin(); it != now->s.end() ; ++it){ print(dep+1,*it); } } void hire(string n1,string n2){ Tman* f = hash[n1]; Tman* s = new Tman(); s->name = n2; s->f = f; f->s.push_back(s); hash[n2] = s; } void fire(string n1){ Tman* s = hash[n1]; Tman* f = s->f; hash.erase(n1); while(s->s.size() != 0){ s->name = s->s.front()->name; hash[s->name] = s; s = s->s.front(); } s->f->s.remove(s); delete s; } void solve(){ string s1,s2; long i; cin >> s1; root = new Tman(); hash[s1] = root; root->name = s1; while(cin >> s1){ if(s1 == "print"){ print(0,root); for(i = 1 ; i <= 60 ; ++i){ cout<<'-'; } cout<<endl; }else if(s1 == "fire"){ cin >> s2; fire(s2); }else{ cin >> s2; cin >> s2; hire(s1,s2); } } } int main(){ solve(); return 0; }
|
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com