A1041. Be Unique

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, 104]. 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.

Input Specification:

Each input file contains one test case. Each case contains a line which begins with a positive integer N (<=105) and then followed by N bets. The numbers are separated by a space.

Output Specification:

For each test case, print the winning number in a line. If there is no winner, print "None" instead.

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

 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 int hashTB[10001] = {0,0}, record[100000];
 5 int main(){
 6     int N, find = -1;
 7     scanf("%d", &N);
 8     for(int i = 0; i < N; i++){
 9         scanf("%d", &record[i]);
10         hashTB[record[i]]++;
11     }
12     for(int i = 0; i < N; i++){
13         if(hashTB[record[i]] == 1){
14             find = i;
15             break;
16         }
17     }
18     if(find == -1)
19         printf("None");
20     else printf("%d", record[find]);
21     cin >> N;
22     return 0;
23 }
View Code

 

总结:

1、本题题意:按照输入的顺序,找出第一个只出现一次的数字并输出。

posted @ 2018-02-02 09:31  ZHUQW  阅读(160)  评论(0编辑  收藏  举报