原题:http://acm.hdu.edu.cn/showproblem.php?pid=2094
最近很喜欢用map
把成功者、失败者都存起来
然后在成功者里把曾经失败的划掉
最后成功者里如果只剩一个人,冠军产生,否则不产生
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
map<string,bool> m1;
string lose[1000];
int n;
while(cin>>n && n)
{
m1.erase(m1.begin(), m1.end());
string a;
for(int i=0; i<n; i++)
{
cin>>a>>lose[i];
m1[a]=true;
}
for(int i=0; i<n; i++)
{
if(m1.find(lose[i])!=m1.end())
{
m1.erase(lose[i]);
}
}
if(m1.size()==1)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
}
return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)