HDU 2094 产生冠军(set)

题目

代码

#include <bits/stdc++.h>
using namespace std;
int main()
{
    
    
    int n;
    set <string> s1,s2;
    string str1,str2;
    while (cin>>n&&n)
    {
    
    
        s1.clear();
        s2.clear();
        while (n--)
        {
    
    
            cin>>str1>>str2;
            s1.insert(str1);
            s1.insert(str2);
            s2.insert(str2);
        }
        if (s1.size()-s2.size()!=1) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}

理解

运用了set在这里插入图片描述
所以在这里只需要找出总人数和失败过的人数差是否唯一,即可得出是否能够找到唯一的冠军。

猜你喜欢

转载自blog.csdn.net/weixin_44918971/article/details/95616202