首页 > 其他 > 详细

PAT_A1041#Be Unique

时间:2019-07-21 21:13:59      阅读:66      评论:0      收藏:0      [点我收藏+]

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:

  • 哈希映射

Code:

 1 /*
 2 Data: 2019-07-21 20:19:03
 3 Problem: PAT_A1041#Be Unique
 4 AC: 07:07
 5 
 6 题目大意:
 7 找出数列中仅出现一次的数
 8 */
 9 
10 #include<cstdio>
11 using namespace std;
12 const int M=1e5+10;
13 int lot[M],mp[M]={0};
14 
15 int main()
16 {
17 #ifdef    ONLINE_JUDGE
18 #else
19     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 }

 

PAT_A1041#Be Unique

原文:https://www.cnblogs.com/blue-lin/p/11222571.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!