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. python输出的高亮显示

    一.语法 1.书写格式 开头部分: \033[显示方式;前景色;背景色m 结尾部分: \033[0m   例如:\033[31;1m测试的文字部分\033[0m   注意: 开头部分的三个参数:显示方 ...

  2. scrapy框架之Pipeline管道类

    Item Pipeline简介 Item管道的主要责任是负责处理有蜘蛛从网页中抽取的Item,他的主要任务是清洗.验证和存储数据.当页面被蜘蛛解析后,将被发送到Item管道,并经过几个特定的次序处理数 ...

  3. xml详解

    https://www.cnblogs.com/zhao1949/p/5652167.html https://www.cnblogs.com/cb0327/p/4967782.html

  4. Web开发入门教程:Pycharm轻松创建Flask项目

    Web开发入门教程:Pycharm轻松创建Flask项目 打开Pycharm的file,选择创建新的项目,然后弹出对话框,我们可以看到里面有很多的案例,Flask.Django等等,我们选择生成Fla ...

  5. IntelliJ IDEA 设置忽略SVN文件和文件夹

       IntelliJ IDEA 在提交文件至SVN时,可以设置忽略某些文件和文件夹,以免误提交不需要提交的文件.最后,插个题外话,介绍一下如何设置代码默认折叠或者展开.下面使用IntelliJ ID ...

  6. Apache Flink - 配置依赖,连接器,库

    每个Flink程序都依赖于一组Flink库. 1.Flink核心和应用程序依赖项 Flink本身由一组类和运行需要的依赖组成.所有类和依赖的组合形成了Flink运行时的核心,并且当一个Flink程序运 ...

  7. 利用 force index优化sql语句性能

    [转自:https://blog.csdn.net/bruce128/article/details/46777567]并进行总结 今天写了一个统计sql,在一个近亿条数据的表上执行,200s都查不出 ...

  8. 一步一步学习FastJson1.2.47远程命令执行漏洞

    本文首发于先知:https://xz.aliyun.com/t/6914 漏洞分析 FastJson1.2.24 RCE 在分析1.2.47的RCE之前先对FastJson1.2.24版本中的RCE进 ...

  9. Jmeter Web 性能测试入门 (五):Jmeter 参数化 Request

    用来参数化的常用方法: 添加配置元件:用户定义的变量 使用函数助手 添加配置元件:CSV Data Set Config 添加前置处理器:BeanShell PreProcessor 添加配置元件:用 ...

  10. Node.js中npm常用命令大全

    npm是什么 NPM的全称是Node Package Manager,是随同NodeJS一起安装的包管理和分发工具,它很方便让JavaScript开发者下载.安装.上传以及管理已经安装的包. npm ...