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
思路
  • map容器记录字符出现的次数,同时另开一个数组record记录输入的顺序
  • 读完之后扫描record,依次判断是否是unique
代码
#include<bits/stdc++.h>
using namespace std;
int record[10010];
int len = 0;
int main()
{
int n;
scanf("%d", &n); int t;
map<int,int> mp;
for(int i=0;i<n;i++)
{
scanf("%d", &t);
if(mp.count(t) == 0) //判断是否之前有出现过
{
record[len++] = t; //记录读进来的顺序
mp[t] = 1;
}else mp[t]++; //否则出现次数+1
}
for(int i=0;i<len;i++)
{
if(mp[record[i]] == 1)
{
printf("%d\n", record[i]);
return 0;
}
}
printf("None\n");
return 0;
}
引用

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

PTA(Advanced Level)1041.Be Unique的更多相关文章

  1. PAT (Advanced Level) 1041. Be Unique (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  2. PTA(Advanced Level)1036.Boys vs Girls

    This time you are asked to tell the difference between the lowest grade of all the male students and ...

  3. PTA (Advanced Level) 1007 Maximum Subsequence Sum

    Maximum Subsequence Sum Given a sequence of K integers { N​1​​, N​2​​, ..., N​K​​ }. A continuous su ...

  4. PTA (Advanced Level) 1004 Counting Leaves

    Counting Leaves A family hierarchy is usually presented by a pedigree tree. Your job is to count tho ...

  5. PTA (Advanced Level) 1021 Deepest Root

    Deepest Root A graph which is connected and acyclic can be considered a tree. The hight of the tree ...

  6. PTA (Advanced Level) 1022 Digital Library

    Digital Library A Digital Library contains millions of books, stored according to their titles, auth ...

  7. PTA (Advanced Level) 1020 Tree Traversals

    Tree Traversals Suppose that all the keys in a binary tree are distinct positive integers. Given the ...

  8. PTA (Advanced Level) 1018 Public Bike Management

    Public Bike Management There is a public bike service in Hangzhou City which provides great convenie ...

  9. PTA (Advanced Level) 1010 Radix

    Radix Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? ...

随机推荐

  1. PHP mysqli_dump_debug_info() 函数

    mysqli_dump_debug_info() 函数转储调试信息到日志中. <?php mysqli_dump_debug_info($con); ?>

  2. Druid连接池 属性说明

    1.1 maxActive 连接池支持的最大连接数.一般取值20就可以了,一般把maxActive设置成可能的并发量就行了设 0 为没有限制. 1.2 maxIdle 连接池中最多可空闲maxIdle ...

  3. js实现上传文件夹

    上传大文件的解决方案 需求:项目要支持大文件上传功能,经过讨论,初步将文件上传大小控制在500M内,因此自己需要在项目中进行文件上传部分的调整和配置,自己将大小都以501M来进行限制. 第一步: 前端 ...

  4. windows中命令行窗口提权到管理员权限.windows 的 sudo

    命令行环境中获取管理员权限 第一种方法 (最爽,但是被运行的命令会被当成新进程运行,运行完成后就自动关闭了.) 把以下代码复制到记事本中保存为sudo.vbs 然后移动到PATH任意目录中,如wind ...

  5. mac 安装docker

    下载地址: https://download.docker.com/mac/stable/Docker.dmg 从应用中找到 Docker 图标并点击运行.可能会询问 macOS 的登陆密码,输入即可 ...

  6. Shell基础之四 变量与运算

    shell变量与运算 变量存在于内存中.假设变量str,设置或修改变量属性时,不带$号,只有引用变量的值时才使用$号.也就是说在内存中,标记变量的变量名称是str,而不是$str. 变量数据的存储方式 ...

  7. docker运行puppeteer出现Page crash解决方案

    Docker默认文件空间64MB.如果puppeteer运行的时候超过这个内存就出现了.Page crash.可以使用docker run --shm-size=256m指定一个更大的内存即可.

  8. 蚁群算法求解TSP问题

    一.蚁群算法简介 蚁群算法是对自然界蚂蚁的寻径方式进行模似而得出的一种仿生算法:蚂蚁在运动过程中,能够在它所经过的路径上留下信息素(pheromone)的物质进行信息传递,而且蚂蚁在运动过程中能够感知 ...

  9. guava常用集合交集,差集,并集,补集操作

    <!-- https://mvnrepository.com/artifact/com.google.guava/guava --> <dependency> <grou ...

  10. IO调度 | Linux块设备中的IO路径及调度策略

    当文件系统通过submit_bio提交IO之后,请求就进入了通用块层.通用块层会对IO进行一些预处理的动作,其目的是为了保证请求能够更加合理的发送到底层的磁盘设备,尽量保证性能最佳.这里面比较重要的就 ...