神的游戏-抱对or淘汰

神的游戏-抱对or淘汰
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic Discuss
Problem Description

来,被选召的孩纸们,现在我将给你们每人一张卡片,每张卡片上都随机生成一个整数,接着每个人都可以在拥有相同数字的人中任选一个配成一对,那么最后余下不能配对的人将被淘汰。我保证每一轮有且仅有一人会被淘汰。来吧,孩纸们,这是运气和魅力的双重考验!
至于你,作为神的侍从,需要把将被淘汰的人所持有的数字实时地告诉他。
Input

多组输入,直到EOF结束。
每组第一行,输入一个正奇数n,表示每一轮的人数。
第二行输入n个整数ai,表示这一轮每个孩纸分到的数字。
0 < n < 100,000; -10^10 < ai < 10^19, 0 < i <= n
Output

每组输出一个整数,即被淘汰的人所持有的数字。
Sample Input

9
1 2 5 5 2 3 3 1 1
9
2 2 3 3 2 3 3 3 3
Sample Output

1
2
Hint

注意输入超过 int 范围
Source
一位大佬写的C++,map做法

#include <iostream>
#include<map>
#include<cstdio>
using namespace std;
char s[100010][20];
int main()
{
    int n;
    map<string,int>mp;
    while(scanf("%d",&n)!=EOF)
    {
        mp.clear();
        for(int i=0; i<n; i++)
        {
            scanf("%s",s[i]);
            mp[s[i]]++;
        }
        map<string,int>::iterator it;
        for(it=mp.begin(); it!=mp.end(); it++)
        {
            if(it->second%2!=0)
            {
                cout<<it->first<<endl;
                break;
            }
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41938269/article/details/82497485