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. java获取web项目下文件夹的路径方法

    方法一: String realPath=request.getSession().getServletContext() .getRealPath("upload"); 方法二: ...

  2. Integer int auto-boxing auto-unboxing ==

    Auto-boxing 自动装箱 Auto-unboxing 自动拆箱 == 相等 1.new出来的对象,除非遇到了拆箱的情况,肯定不相等. 因为new对象之前需要在JVM堆中提供空间,所以new出来 ...

  3. ICEM-五通孔管

    原视频下载地址:https://yunpan.cn/cqaQ2t5DrRcKa  访问密码 d111

  4. 去除IntelliJ IDEA对重复代码的检测

    方法1:  方法2:(比较简便) 

  5. Jmeter Web 性能测试入门 (一):环境配置 (免安装版)

    去官网下载并安装java jdk8 去官网下载jmeter binaries最新的zip,并解压到某路径下.(注:由于jmeter-server的限制,放置的路径不要太长,路径不要带空格,例如:D:\ ...

  6. zookeeper源码 — 五、处理写请求过程

    目录 处理写请求总体过程 客户端发起写请求 follower和leader交互过程 follower发送请求给客户端 处理写请求总体过程 zk为了保证分布式数据一致性,使用ZAB协议,在客户端发起一次 ...

  7. mysql —复制

    MySQL的扩展 读写分离  复制:每个节点都有相同的数据集 向外扩展 二进制日志 单向 复制的功用: 数据分布 负载均衡读 备份 高可用和故障切换 MySQL升级测试 MySQL复制相关概念 主从复 ...

  8. Mac OS 下三种修改Hosts文件的方法

    一.系统偏好设置修改 1.打开系统偏好设置,底部有一个Hosts的快捷入口2.输入ip和hostname后,回车确定,勾选改host即可   二.终端命令行修改 sudo vi /etc/hosts ...

  9. HearthAgent A Hearthstone agent

    http://www.intelligence.tuc.gr/~robots/ARCHIVE/2015w/Projects/LAB51326833/download.html The project ...

  10. mysql数据库每个表的备份脚本

    对mysql数据库中的每张表进行按日期备份,思想是:先把每张表的表名取出取出,然后通过for循环去对每个表进行按日期备份 [root@ZFVM-APP-- backup]# vim dataname. ...