PAT 甲级 1041 Be Unique (20 分)

1041 Be Unique (20 分)

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<iostream>
 2 #include<map>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int N, temp, index = 1, min = 999999;
 9     map<int, int> m;
10 
11     cin >> N;
12 
13     for (int i = 0; i<N; ++i)
14     {
15         cin >> temp;
16 
17         if (m.find(temp) == m.end())
18             m.insert(pair<int, int>(temp, index++));
19         else
20             m[temp] = 0;
21     }
22 
23     map<int, int>::iterator begin = m.begin(), end = m.end(), i, minIndex;
24 
25     for (i = begin; i != end; ++i)
26     {
27         if (i->second>0 && i->second<min)
28         {
29             min = i->second;
30             minIndex = i;
31         }
32     }
33 
34     if (min == 999999)
35         cout << "None" << endl;
36     else
37         cout << minIndex->first << endl;
38 }

 

posted on 2019-01-06 17:34  么么打123  阅读(151)  评论(0编辑  收藏  举报