Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register
欢迎参加IJCAI 2020麻将智能体竞赛,大奖等你拿!Welcome to IJCAI 2020 Mahjong AI competition with amazing prizes! | 北京大学《ACM/ICPC大学生程序设计竞赛训练》暑期课面向全球招生!

贴个代码

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:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator