A1041 Be Unique (20 point(s))

寻找只出现一次的数

1. 原文

原题

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:

1
7 5 31 5 88 67 88 17

Sample output 1:

1
31

Sample Input 2:

1
5 888 666 666 888 888

Sample output 2:

1
None

2. 解析

输出仅出现一次的数

3. AC代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<cstdio>
#include<map>
using namespace std;
map<int,int> exist;
int num[100010]={};
int main()
{
int n;
scanf("%d",&n);
for (int i = 0; i < n; ++i)
{
scanf("%d",&num[i]);
exist[num[i]]++;
}
int flag=0;
for (int i = 0; i < n; ++i)
{
if (exist[num[i]]==1)
{
flag=1;
printf("%d\n", num[i]);
break;
}
}
if (flag==0)
{
printf("None\n");
}
return 0;
}
本文结束  感谢您的阅读
  • 本文作者: Wang Ting
  • 本文链接: /zh-CN/2019/09/03/A1041/
  • 发布时间: 2019-09-03 12:34
  • 更新时间: 2021-10-29 14:00
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!

Related Issues not found

Please contact @WTlumos to initialize the comment