题目

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, 10^4]. 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(<=10^5) 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

题目分析

已知一系列数,找到第一个不重复的数字

解题思路

  1. 定义数组ns[N],存放输入数字
  2. 定义数组ts[10001],记录输入数字出现次数
    • 大小为10001,(题目已知:输入数字取值范围[1, 10^4])
    • 数组下标--输入数字
    • 数组元素--输入数字出现次数
  3. 遍历输入数字(ns数组),最早出现次数==1(表明是唯一数),打印退出

易错点

  1. 若没有唯一数时,打印None,注意None后不需要加"\n"就可以AC

Code

Code 01

#include <iostream>
//#include <>
using namespace std;
int main(int argc, char * argv[]){
int N,m;
scanf("%d",&N);
int ns[N];
int ts[10001]={0};
for(int i=0;i<N;i++){
scanf("%d",&ns[i]);
ts[ns[i]]++;
}
bool flag = false;
for(int i=0;i<N;i++){
if(ts[ns[i]]==1){
printf("%d",ns[i]);
flag = true;
break;
}
}
if(!flag)printf("None");
return 0;
}

PAT Advanced 1041 Be Unique (20) [Hash散列]的更多相关文章

  1. PAT Advanced 1084 Broken Keyboard (20) [Hash散列]

    题目 On a broken keyboard, some of the keys are worn out. So when you type some sentences, the charact ...

  2. PAT Advanced 1050 String Subtraction (20) [Hash散列]

    题目 Given two strings S1 and S2, S = S1 – S2 is defined to be the remaining string afer taking all th ...

  3. PAT Advanced 1041 Be Unique (20 分)

    Being unique is so important to people on Mars that even their lottery is designed in a unique way. ...

  4. PAT Advanced 1048 Find Coins (25) [Hash散列]

    题目 Eva loves to collect coins from all over the universe, including some other planets like Mars. On ...

  5. PAT Advanced 1134 Vertex Cover (25) [hash散列]

    题目 A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at ...

  6. PAT Basic 1047 编程团体赛(20) [Hash散列]

    题目 编程团体赛的规则为:每个参赛队由若⼲队员组成:所有队员独⽴⽐赛:参赛队的成绩为所有队员的成绩和:成绩最⾼的队获胜.现给定所有队员的⽐赛成绩,请你编写程序找出冠军队. 输⼊格式: 输⼊第⼀⾏给出⼀ ...

  7. PAT甲 1041. Be Unique (20) 2016-09-09 23:14 33人阅读 评论(0) 收藏

    1041. Be Unique (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Being uniqu ...

  8. PAT 甲级 1041 Be Unique (20 分)(简单,一遍过)

    1041 Be Unique (20 分)   Being unique is so important to people on Mars that even their lottery is de ...

  9. PAT Advanced 1092 To Buy or Not to Buy (20) [Hash散列]

    题目 Eva would like to make a string of beads with her favorite colors so she went to a small shop to ...

随机推荐

  1. XPath--快速获取XML数据的节点或属性

    转载自 XPath可以快速定位到Xml中的节点或者属性.XPath语法很简单,但是强大够用,它也是使用xslt的基础知识.示例Xml: <?xml version="1.0" ...

  2. [Updating]点分治学习笔记

    Upd \(2020/2/15\),又补了一题 LuoguP2664 树上游戏 \(2020/2/14\),补了一道例题 LuoguP3085 [USACO13OPEN]阴和阳Yin and Yang ...

  3. junit基础学习之-测试service层(3)

    测试步骤: 在之前的文章中已经加了junit的环境,这就不需要了. 1.加载junit类,spring配置文件,指明junit测试器,@Runwith 2.定义变量,service,不可以使用spri ...

  4. spring学习第7天(PCD以及切点表达式)

    1.PCD(PointCutDesigner) spring的aop只针对方法进行aop代理,而apectj联盟的aop比之更加强大,还可以针对字段等进行切面编程 1.1:execution,用的最多 ...

  5. 动态添加,删除class样式

    function hasClass(obj, cls) { //class位于单词边界,判断class样式是否已经存在 return obj.className.match(new RegExp('( ...

  6. Linux基础操作及概念

    Linux基础操作及概念 终端的概念 通常我们在使用 Linux 时,并不是直接与系统打交道,而是通过一个叫做 Shell 的中间程序来完成的,在图形界面下为了实现让我们在一个窗口中完成用户输入和显示 ...

  7. app页面连接到服务器的数据库

    第一步在服务器上写好servlet用于和数据库交互,目前我只写了添加. 第二步app端使用HttpURLConnection连接交互. 效果图: 增加了一条数据:第十一条

  8. HDU 5464:Clarke and problem

    Clarke and problem  Accepts: 130  Submissions: 781  Time Limit: 2000/1000 MS (Java/Others)  Memory L ...

  9. RFX2401C与RFX2402E的区别

    随着科技的发展,射频设备也慢慢的普及,射频放大器在射频设备中起着非常重要的作用.为了能获得足够大的距离,必须都要外加射频信号放大器. 射频信号放大器简称 “PA”.PA主流应用主要有ZigBee .无 ...

  10. cf442 B.Andrey and Problem

    看题偷瞄到题解2333(以为是劲题呢..结果是乱贪心,奇怪) 排序之后,如果加入下一个比现在更优就更新答案(奇怪啊) t=ans*(1-a[i])+s*a[i];(ans*(1-a[i])是新的一位不 ...