PAT_A1041#Be Unique

Source:

PAT A1041 Be Unique (20 分)

Description:

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]. 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(≤) 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

Keys:

  • Hash map

Code:

. 1  / * 
2  the Data: 2019-07-21 20:19:03
 . 3  Problem: PAT_A1041 of Unique # of Be
 . 4  the AC: 07:07
 . 5  
. 6  subject to the effect:
 7  to find the number of column number only appears once
 8  * / 
. 9  
10 # the include <cstdio>
 . 11  the using  namespace STD;
 12 is  const  int M + 1E5 = 10 ;
 13 is  int Lot [M], MP [M] = { 0 };
 14  
15  int main ()
 16  {
 . 17  #ifdef ONLINE_JUDGE
 18 is  #else 
. 19      The freopen ( 'Test.txt", "r", stdin);
20 #endif
21 
22     int n;
23     scanf("%d", &n);
24     for(int i=0; i<n; i++)
25     {
26         scanf("%d", &lot[i]);
27         mp[lot[i]]++;
28     }
29     for(int i=0; i<n; i++)
30     {
31         if(mp[lot[i]]==1)
32         {
33             printf("%d", lot[i]);
34             n=0;break;
35         }
36     }
37     if(n)   printf("None");
38 
39     return 0;
40 }

 

Guess you like

Origin www.cnblogs.com/blue-lin/p/11222571.html