PAT 甲级 1041 Be Unique

https://pintia.cn/problem-sets/994805342720868352/problems/994805444361437184

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, 10^4^]. 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

代码:
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 10;
int a[maxn], num[maxn];

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++) {
        scanf("%d", &a[i]);
        num[a[i]] ++;
    }

    int cnt = 0;
    for(int i = 1; i <= n; i ++) {
        if(num[a[i]] == 1) {
            printf("%d\n", a[i]);
            return 0;
        }
        if(num[a[i]] > 1)
            cnt ++;
    }
    if(cnt == n)
        printf("None\n");
    return 0;
}

  

原文地址:https://www.cnblogs.com/zlrrrr/p/9426365.html

时间: 2024-11-05 21:45:52

PAT 甲级 1041 Be Unique的相关文章

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]. The first one who bets on a unique number wins. For example

PAT Advanced 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]. The first one who bets on a unique number wins. For example, if there are 7 peopl

PAT Advanced 1041 Be Unique (20) [Hash散列]

题目 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, 10^4]. The first one who bets on a unique number wins. For example, if there ar

PAT:1041. Be Unique (20) AC “段错误:可能是数组开的不够大”

#include<stdio.h> #include<string.h> int harsh[10066]; int arr[100066]; int main() { memset(harsh,0,sizeof(harsh)); memset(arr,0,sizeof(arr)); int n; scanf("%d",&n); for(int i=0 ; i<n ; ++i) { int tmp; scanf("%d",&am

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 on

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,10?4??]. The first one who bets on a unique number wins. For e

PAT甲级1005 Spell It Right

题目:PAT甲级 1005 题解:水题.看到题目的第一时间就在想一位一位的mod,最后一加一转换就完事了.结果看到了N最大为10的100的次方,吓得我赶紧放弃这个想法... 发现碰到这种情况用字符串十分好用,这道题应该考察的就是这一点.大致思路就是把数字的每一位放到字符串中,然后通过ASCII码得到每一位的相加结果num,然后把num一位一位的放到stack中,使用stack是因为它先进先出的特性,最后输出就行了. 代码: 1 #include<cstdio> 2 #include<qu

1041. Be Unique

1041. Be Unique (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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 fr

PAT甲级考前整理

终于在考前,刷完PAT甲级130道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种境界.PAT甲级题目总的说卡题目的比较多,卡测试点的比较少,有些题目还会有题意混淆,这点就不吐槽了吧.静下心来耍这130道题,其实磨练的是一种态度与手感,养成的是一种习惯.热爱AC没有错!! 130道题目主要的考点: 1.排序:快速排序,直接插入排序,希尔排序,分治排序,堆排序. 2.图论:拓扑排序.最短路径.深度搜索.广度搜索. 3.树:树的遍历.完全二叉树.AVL. 4.其他:并查集,模拟,哈希.背包.