若输入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;
}

相关文章:

  • 2021-06-03
  • 2021-10-24
  • 2021-11-26
  • 2022-12-23
  • 2021-07-29
  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-27
  • 2021-05-18
  • 2021-08-25
  • 2022-01-06
  • 2022-12-23
  • 2022-12-23
  • 2022-03-05
相关资源
相似解决方案