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

当map容器练练手,挺好的题

Posted by 15211160230 at 2016-12-06 21:09:09 on Problem 2491
#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:
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