题目描述
Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1, 10^4]. The first one who bets on a unique number wins. For example, if there are 7 people betting on 5 31 5 88 67 88 17, then the second one who bets on 31 wins.
翻译:对于在火星上的人来说独特是很重要的,甚至他们的彩票都设计的很奇特。胜利的方式很简单:一个人选择 [1, 10^4]中的一个数字。第一个选中的独一无二的数字的人胜利。举个例子,如果有7个人分别竞猜 5 31 5 88 67 88 17,那么第二个即猜31的人胜利。
INPUT FORMAT
Each input file contains one test case. Each case contains a line which begins with a positive integer N (<=10^5) and then followed by N bets. The numbers are separated by a space.
翻译:每个输入文件包含一组测试数据。对于每组输入数据,第一行以正整数N (<=10^5) 开始,接着是N个竞猜的数字。数字间用空格隔开。
OUTPUT FORMAT
For each test case, print the winning number in a line. If there is no winner, print “None” instead.
翻译:对于每组输入数据,输出一行胜利数字。如果没有胜者,则输出“None”
Sample Input 1:
7 5 31 5 88 67 88 17
Sample Output 1:
31
Sample Input 2:
5 888 666 666 888 888
Sample Output 2:
None
解题思路
模拟题目描述即可,注意是最先出现的数字。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#define INF 99999999
using namespace std;
int Hash[10010];
int d[10010],ccount=0;
int N;
int main(){
scanf("%d",&N);
int a;
for(int i=0;i<N;i++){
scanf("%d",&a);
Hash[a]++;
if(Hash[a]==1)d[ccount++]=a;
}
int flag=0;
for(int i=0;i<ccount;i++){
if(Hash[d[i]]==1){
printf("%d\n",d[i]);
flag=1;
break;
}
}
if(!flag)printf("None\n");
return 0;
}