hdu 2094 产生冠军

若输入A 战胜 B时,就让B指向A。
最后,指向空的就说明没有人战胜过他。如果这样的人只存在一个,那他就是冠军了。

名字的映射用map实现,出现过的名字用set保存

#include <set>
#include <map>
#include <string>
#include <iostream>
using namespace std;

int main(void)
{
    int n, i, t;
    string b, e;
    set <string> s;
    set <string>::iterator it;
    map <string, string> m;
    map <string, string>::iterator iter;

    while (cin >> n, n)
    {
        s.clear();
        m.clear();
        for (i = 0; i < n; i++)
        {
            cin >> b >> e;
            s.insert(b);
            s.insert(e);
            m[e] = b;
        }
        for (t = 0, it = s.begin(); it != s.end(); it++)
        {
            if (!m[*it].length())
                t++;
        }
        puts(t == 1 ? "Yes" : "No");
    }

    return 0;
}

原文地址:https://www.cnblogs.com/nanke/p/2169989.html