1041. Be Unique (20)【水题】——PAT (Advanced Level) Practise

题目信息

1041. Be Unique (20)

时间限制100 ms

内存限制65536 kB

代码长度限制16000 B

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 (<=10^5) 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

解题思路

记录每个数出现次数,第一个出现一次的为所求

AC代码

#include <cstdio>
#include <map>
#include <vector>
using namespace std;
int main()
{
    int n, t;
    vector<int> v;
    map<int, int> mp;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i){
        scanf("%d", &t);
        v.push_back(t);
        mp[t]++;
    }
    bool flag = false;
    for (int i = 0; i < v.size(); ++i){
        if (mp[v[i]] == 1){
            printf("%d\n", v[i]);
            flag = true;
            break;
        }
    }
    if (!flag){
        printf("None\n");
    }
    return 0;
}
时间: 2024-08-25 09:09:52

1041. Be Unique (20)【水题】——PAT (Advanced Level) Practise的相关文章

1093. Count PAT&#39;s (25)【计数】——PAT (Advanced Level) Practise

题目信息 1093. Count PAT's (25) 时间限制120 ms 内存限制65536 kB 代码长度限制16000 B The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th c

1084. Broken Keyboard (20)【字符串操作】——PAT (Advanced Level) Practise

题目信息 1084. Broken Keyboard (20) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen. Now given a string that

1092. To Buy or Not to Buy (20)【水题】——PAT (Advanced Level) Practise

题目信息 1092. To Buy or Not to Buy (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner o

1083. List Grades (25)【水题】——PAT (Advanced Level) Practise

题目信息 1083. List Grades (25) 时间限制400 ms 内存限制65536 kB 代码长度限制16000 B Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of w

1015. Reversible Primes (20) ——PAT (Advanced Level) Practise

题目信息: 1015. Reversible Primes (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73

1008. Elevator (20)——PAT (Advanced Level) Practise

题目信息: 1008. Elevator (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator w

1001. A+B Format (20) ——PAT (Advanced Level) Practise

题目信息: 1001. A+B Format (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than

1005. Spell It Right (20)——PAT (Advanced Level) Practise

题目信息: 1005. Spell It Right (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English. Input Specificat

1011. World Cup Betting (20)——PAT (Advanced Level) Practise

题目信息: 1011. World Cup Betting (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing