您的位置:首页 > 其它

hdu 2094 产生冠军

2010-09-06 09:30 507 查看
问题描述:

      给N个比赛的结果,求能不能产生冠军

解决方法:

      只有当都没有输过一场比赛的人数为1时,就能产生冠军,否则不能。

代码如下:

/*
Author: ACb0y
Date: 2010年9月6日9:21:47
Type: Water()
ProblemId:hdu 2094 产生冠军
Result: 2923032 2010-09-06 09:20:14 Accepted 2094 31MS 276K 643 B C++ ACb0y
*/
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main()
{
int n;
#ifndef ONLINE_JUDGE
freopen("2094.txt", "r", stdin);
#endif
while (cin >> n)
{
if (n == 0) {
break;
}
string a, b;
map<string, int> m;
for (int i = 0; i < n; i++)
{
cin >> a >> b;
if (m.find(a) == m.end()) {
m[a] = 0;
}
if (m.find(b) == m.end()) {
m[b] = -1;
} else {
m[b]--;
}
}
int c = 0;
map<string, int>::iterator it;
for (it = m.begin(); it != m.end(); it++) {
if (it->second == 0) {
c++;
}
}
if (c == 1) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iterator string 2010 c