Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 贴个代码

Posted by Yt_zp at 2015-08-22 15:17:01 on Problem 2003
```#include <map>
#include <list>
#include <cstdio>
#include <string>
#include <iostream>
#define maxn 100
using namespace std;
struct Tman{
string name;
Tman *f;                ///父指针
list<Tman *>s;           ///储存儿子的队列指针s
Tman(){f=NULL;}
};
map<string,Tman*> hash;     ///hash[x]存储成员名为x的根子树指针
Tman *root;
void print(long dep,Tman *now){
if(now==NULL)return;
for(long i=1;i<=dep;++i)
putchar('+');
printf("%s\n",now->name.c_str());
for(list<Tman*>::iterator j=now->s.begin();j!=now->s.end();++j)
print(dep+1,*j);
}
void hiers(string a,string b){
Tman*f=hash[a];
Tman*s=new Tman();
s->name=b;
s->f=f;
f->s.push_back(s);
hash[b]=s;
}
void fire(string t){
Tman*s=hash[t];
Tman*f=s->f;
hash.erase(t);
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;
}
int main(){
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)
putchar('-');
putchar('\n');
}
else if(s1=="fire"){
cin>>s2;
fire(s2);
}
else {
cin>>s2;
cin>>s2;
hiers(s1,s2);
}
}
return 0;
}
```

Followed by:

User ID:
Title:

Content: