产生冠军 航电2094 set应用

题解

冠军只能有一个,记录总人数及失败的人数,因为冠军是从未失败过的,所以如果有冠军,则 总人数-失败人数=1

#include <iostream>
#include <vector>
#include <set>
using namespace std;
int main()
{
    
    
    int N;
    while (scanf("%d", &N) && N != 0)
    {
    
    
        set<string> ret_1;
        set<string> ret_2;
        string a, b;
        while (N--)
        {
    
    
            cin >> a >> b;
            ret_1.insert(a);
            ret_1.insert(b);
            ret_2.insert(b);
        }
        cout << (ret_1.size() - ret_2.size() != 1 ? "No" : "Yes");
        cout << endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_45653525/article/details/112976542