| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
当map容器练练手,挺好的题#include <iostream>
#include <string>
#include <map>
#include <utility>
using namespace std;
int main()
{ int T,n,len=0;
string s,t,start;
map<string,string>flow,rflow;
map<string,string>::iterator it;
cin>>T;
while(T--)
{ cin>>n;
flow.clear(),rflow.clear();
for(int i=0;i<n-1;++i)
{ cin>>s>>t;
flow.insert(make_pair(s,t));
rflow.insert(make_pair(t,s));
}
for(it=rflow.begin();it!=rflow.end();it++)
{ if(rflow.find(it->second)==rflow.end())
{ start=it->second;
break;
}
}
cout<<"Scenario #"<<++len<<":"<<endl;
cout<<start<<endl;
it=flow.find(start);
while(it!=flow.end())
{ cout<<it->second<<endl;
it=flow.find(it->second);
}
cout<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator