codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include<iostream> #include<cstdio> #include<cstdlib> #include<ctime> #include<utility> #include<algorithm> #include<vector> #include<queue> #include<set> #include<map> #include<cmath> #include<cstring> #include<cctype> #include<string> #include<string.h>//******** #include<list> using namespace std; struct Tman { string name; Tman *f; list<Tman *> s; Tman() {f=NULL;} }; typedef long long ll; string s1,s2; map<string,Tman *> hash; Tman *root; void print(ll dep,Tman *s) { if(s==NULL) return; for(ll i=1;i<=dep;i++) cout<<'+'; cout<<s->name<<endl; for(list<Tman *>::iterator it=s->s.begin();it!=s->s.end();it++) print(dep+1,*it); } void fire(string s1) { Tman *s=hash[s1]; hash.erase(s1); 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 hire(string s1,string s2) { Tman *s=new Tman(); Tman *f=hash[s1]; s->f=f; s->name=s2; hash[s2]=s; f->s.push_back(s);//** } int main() { cin>>s1; root=new Tman(); root->name=s1; hash[s1]=root; while(cin>>s1) { if(s1=="print") { print(0,root); for(int i=1;i<=60;i++) cout<<'-'; cout<<endl; } else if(s1=="fire") { cin>>s2; fire(s2); } else { cin>>s2; cin>>s2; hire(s1,s2); } } return 0; }
Private
[
?
]
Run code
Submit