1041 Be Unique

喜欢ヅ旅行 2024-04-08 13:06 168阅读 0赞

1041 Be Unique

0、题目

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

1、大致题意

给n个数字,按照读入顺序,哪个数字是第一个在所有数字中只出现一次的数字。如果所有数字出现都超过了一次,则输出None

2、基本思路

简单题。

建立一个数组,存储每个数字出现的次数,然后遍历一遍输入的顺序看是否有出现次数为1的数字

3、AC代码

  1. #include <cstdio>
  2. using namespace std;
  3. int a[100001], m[100000];
  4. int main() {
  5. int n;
  6. scanf("%d", &n);
  7. for(int i = 0; i < n; i++) {
  8. scanf("%d", &a[i]);
  9. m[a[i]]++;
  10. }
  11. for(int i = 0; i < n; i++) {
  12. if(m[a[i]] == 1) {
  13. printf("%d", a[i]);
  14. return 0;
  15. }
  16. }
  17. printf("None");
  18. return 0;
  19. }

17a0a77b7fe84fe48d196ee4d4fd0a5b.png

发表评论

表情:
评论列表 (有 0 条评论,168人围观)

还没有评论,来说两句吧...

相关阅读

    相关 1041. 考试座位号(15)

    每个PAT考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,

    相关 PAT乙级1041

    1041 考试座位号 (15 分) 每个 PAT 考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常情况下,考生在入场时先得到试机座位号码,入座进入试

    相关 1041 考试座位号

    题目描述   每个 PAT 考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显