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. Reflect对象

    一.Reflect对象基础 Reflect对象是ES6出现的新的API,用于操作对象内部的方法. 特点: 1. 对于操作有明确的返回结果.如返回布尔值表示操作成功与否 2. 和Proxy的拦截方法一一 ...

  2. RabbitMq、ActiveMq、Kafka和Redis做Mq对比

    转载自:https://blog.csdn.net/qiqizhiyun/article/details/79848834 一.RabbitMq RabbitMQ是一个Advanced Message ...

  3. Codeforces 1180E Serge and Dining Room

    题意: 有\(n\)个菜肴,有\(m\)个小朋友,每个菜肴的价格为\(a_i\),每个小朋友有\(b_i\)元钱,小朋友从\(1 \rightarrow m\)依次购买菜肴,当第\(i\)个小朋友轮到 ...

  4. DP(第二版)

    第一版请见:直通 话不多说,直接上题 1.P1040 加分二叉树 直通 思路: 已知中序遍历,相当于一段区间了,所以我们枚举一个k,如果以k为根节点,能够将分数更新,那么这段区间的根节点就置为k,最后 ...

  5. Noip2014 提高组 Day1 T1 生活大爆炸版石头剪刀布 + Day2 T1 无线网络发射器选址

    Day1 T1 题目描述 石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一样,则不分胜负.在<生活大爆炸>第二季第8 集中出现了一种石头剪刀布的升级版游戏. 升 ...

  6. c++问题集合

    1.对于程序未运行和运行后的代码段到底存储什么? 2.编写程序时为什么先申请变量后使用? 3.malloc本质到底分配了什么?谁赋给的? 4.程序在系统上是怎么运行起来的? 5.当我们双击一个程序运行 ...

  7. MongoDB-查询关键字/排序等

    查询关键字 并列查询$and # 条件都成立才可以查询到结果 db.stutent.find({$and:[{name:"小漩涡"},{age:30}]}) 或查询$or # 有一 ...

  8. tomcat控制前台到后台的乱码问题

    1.找到tomcat中的conf文件下的server.xml文件. 2.点击打开后找到 <Connector  port="8080" protocol="HTTP ...

  9. make 和 make install 的区别

    简单来说,make 是编译,make install 是安装. 总结:linux编译安装中configure.make和make install各自的作用 ./configure是用来检测你的安装平台 ...

  10. JS合并多个数组去重算法

    var arr1 = ['a','b']; var arr2 = ['a','c','d']; var arr3 = [1,'d',undefined,true,null]; //合并两个数组,去重 ...