首页 > 其他分享 >PAT Advanced 1041 Be Unique(20)

PAT Advanced 1041 Be Unique(20)

时间:2022-09-05 23:27:58浏览次数:57  
标签:bets case 1041 20 int 31 Sample 88 Unique

题目描述:

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:

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

题目大意:

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

#include<iostream>
using namespace std;

const int N = 100010;
int a[N], ha[N];
int n;

int main()
{
    cin >> n;
    for(int i = 0 ; i < n ; i ++)   
    {
        scanf("%d", &a[i]);
        ha[a[i]] ++;
    }
    
    bool flag = false;
    for(int i = 0 ; i < n ; i ++)
        if(ha[a[i]] == 1)
        {
            flag = true;
            cout << a[i];
            break;
        }
    if(!flag)   cout << "None";
    return 0;
}

标签:bets,case,1041,20,int,31,Sample,88,Unique
From: https://www.cnblogs.com/yztozju/p/16660011.html

相关文章

  • 使用Visual Studio2022写汇编 代码自动高亮
     本贴帮助使用VS2022写汇编的小伙伴实现代码自动高亮 今天汇编课程老师要求在本地PC上配置一个可以写汇编的环境,选择使用VS2022以及下载的MASM搭建环境。按照网上教程......
  • 信息学奥赛一本通 1314:【例3.6】过河卒(Noip2002)
    时间限制:1000ms      内存限制:65536KB提交数:26367   通过数:11410【题目描述】棋盘上A点有一个过河卒,需要走到目标B点。卒行走的规则:可以向下......
  • C++11~C++20 新基础类型
    目录整数类型longlong(C++11)字符类型char16_t和char32_t(C++11)C++11为什么要引入char16_t和char32_t?字符类型char8_t(C++20)参考资料整数类型longlong(C++11)C++1......
  • 2022-9-5
    2022-9-5HWS2022-Re1这题也算复习了一下tea,踩了一下几个做题的坑,希望自己下次做tea的时候可以注意1.注意ida的赋值问题,要了解出题人的代码规范和习惯2.注意sum值的变化......
  • 2022 年 9 月水题选做
    20220901SP30919GCDS-Sabbirandgcdproblem思路:显然答案就是不是任意一个数的因数的最小的质数。这个可以在线性筛的时候记录每个数的最小的素因数即可。算法:线性......
  • leetcode206:反转链表
    packagecom.mxnet;importjava.util.Stack;publicclassSolution206{publicstaticvoidmain(String[]args){}/***给你单链表的头节点......
  • 【2022-09-05】Django框架(五)
    Django框架(五)定义模型类fromdjango.dbimportmodels#Createyourmodelshere.classUser(models.Model):uid=models.AutoField(primary_key=True,ver......
  • 220905-读书笔记-把时间当做朋友
    印象中,第一次读这本书的时候,是在大学期间,应该是大一或者大二的时候,当时候自己的智识达不到理解这本书的层次。现在在读这本书,竟觉得略有些浅显。总的来说,这本书写的比较零......
  • I [NOIP2012]开车旅行 每次往第一或者第二近的点走,求最大比值 倍增算法 set
    链接:https://ac.nowcoder.com/acm/problem/16562来源:牛客网题目描述小A和小B决定利用假期外出旅行,他们将想去的城市从1到N编号,且编号较......
  • xx技术2023前端开发卷A
    xx技术2023前端开发卷A选择以下哪种情况会导致浏览器报HTTPS证书告警()网站的https安全证书确实已经过期,根据https安全证书签发国际标准,https安全证书颁发不能超过两......