POJ2003

原创 2018年04月15日 22:25:47


#include<iostream>
#include<list>
#include<map>
#include<string>
using namespace std;
struct Tman
{
	string name;
	Tman *f;
	list<Tman *> s;
	Tman() { f = NULL; }
};
Tman *root;
map<string,Tman *> Hash;
void print(Tman *now,int deep)
{
	for (int i = 0; i < deep; i++)
		cout << '+';
	cout << now->name << endl;
	for (list<Tman *>::iterator it = now->s.begin(); it != now->s.end(); it++)
		print(*it, deep + 1);
}
void fires(string str)
{
	Tman *s = Hash[str];
	Hash.erase(str);
	while (s->s.size())
	{
		s->name = s->s.front()->name;
		Hash[s->name] = s;
		s = s->s.front();
	}
	s->f->s.remove(s);
	delete s;
}
void hires(string str1, string str2)
{
	Tman *s = Hash[str1];
	Tman *ss = new Tman();
	ss->name = str2;
	ss->f = s;
	Hash[str2] = ss;
	s->s.push_back(ss);
}
void solve()
{
	string str, str1;
	cin >> str;
	root = new Tman();
	Hash[str] = root;
	root->name = str;
	while (cin >> str)
	{
		if (str == "print") {
			print(root,0);
			for (int i = 0; i < 60; i++)
				cout << '-';
			cout << endl;
		}
		else if (str == "fire") {
			cin >> str1;
			fires(str1);
		}
		else {
			cin >> str1;
			cin >> str1;
			hires(str, str1);
		}
	}
}
int main()
{
	solve();
	return 0;
}

收藏助手
不良信息举报
您举报文章:POJ2003
举报原因:
原因补充:

(最多只允许输入30个字)