POJ2491 Scavenger Hunt【裸map】

#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <string>
using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE
		freopen("D:/1.txt","r",stdin);
		freopen("D:/2.txt","w",stdout);
	#endif
	int casen;
	cin>>casen;
	int tt=0;
	for(int caset=1;caset<=casen;caset++)
	{
	    map<string,string>path;
        map<string,int>point;
        map<string,int>::iterator it;
		int len;
		cin>>len;
		for(int i=0;i<len-1;i++)
		{
			string s1,s2;
			cin>>s1>>s2;
			path[s1]=s2;
			point[s1]=0;
			point[s2]=1;
		}
		for(it=point.begin();it!=point.end();it++)
		{
			if(it->second==0)
			{
				break;
			}
		}
		string start=it->first;
		//cout<<start<<endl;
		cout<<"Scenario #"<<caset<<":\n";
		cout<<start<<'\n';
		for(int i=0;i<len-1;i++)
		{
			cout<<path[start]<<'\n';
			start=path[start];
		}
		cout<<'\n';
	}
	return 0;
}

posted @ 2017-08-10 10:29  jzdwajue  阅读(133)  评论(0编辑  收藏  举报