http://acm.hdu.edu.cn/showproblem.php?pid=2094

题意:给你n个比赛结果问能不能产生冠军。。

思路:当且仅当只有一个人没有输过一场比赛时。。

#include<map>
#include<iostream>
#include<string.h>
#include<string>
using namespace std;
int main()
{
	int n;
	while(cin>>n&&n)
	{
		map<string,int> m;
		for(int i=0;i!=n;++i)
		{
			string a,b;
			cin>>a>>b;
			if(m.find(a)==m.end())
				m[a]=0;
			if(m.find(b)==m.end())
				m[b]=-1;
			else m[b]--;
		}
		map<string,int>::iterator p;
		int sum=0;
		for(p=m.begin();p!=m.end();++p)
			if(p->second==0) sum++;
		if(sum==1) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}return 0;
}


你可能感兴趣的:(http://acm.hdu.edu.cn/showproblem.php?pid=2094)