题目

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. 055-for循环中break的使用

    <?php ;;$x++){ //省略表达式2的for循环将是无限循环 echo "$x<br />"; ){ break; //使用if语句控制退出无限循环 } ...

  2. 第一个flink application

    导入maven依赖 需要注意的是,如果使用scala写程序,导入的依赖跟java是不一样的 Maven Dependencies You can add the following dependenc ...

  3. ES query does not support [auto_generate_synonyms_phrase_query]

    测试环境使用  elasticsearch-rest-high-level-client  做为基础包发起es调用出现如下异常: {"error":{"root_caus ...

  4. 打包|zip

    原始:gzip zip -r ./gzip.zip ./gzip/* adding: gzip/split_10.gz (deflated 2%) adding: gzip/split_11.gz ( ...

  5. C++ #if 1

    当注释掉大块代码时,使用"#if 0"比使用"/**/"要好,因为用"/**/"做大段的注释要防止被注释掉的代码中有嵌套的"/** ...

  6. Egret Engine 2D - Get Started

    Get Started     Egret 也支持在命令行完成编译,运行,发布等操作.在下面的教程中会穿插对应操作的命令行代码.   可新建游戏项目,也可建eui项目   这里包含默认的几个库,egr ...

  7. java课程之团队开发冲刺阶段2.5

    总结昨天进度: 1.昨天对课前提醒的基本框架已经搭好,剩下的就是对如何提醒进行设置 遇到的困难: 1.在一些细节地方,代码有点犯浑,将Preferences的文件写错了,导致在用switch开关得到时 ...

  8. 渗透测试 - HPP数据污染 - 原理 | 场景

    Web服务器 参数获取函数    获取到的参数 PHP/Apache   $_GET(“par”)  Last JSP/Tomcat   Request.getParameter(“par”)    ...

  9. It can be a face application using SeetaFace and Qt.

    之前编译了一下SeetaFace的库,用于人脸检测.特征点定位和人脸识别的功能,然后昨天就用Qt写了一个软件用于实现. 工程的文件还是比较简单的,一个界面类和一个SeetaFace的线程类而已.这里主 ...

  10. h5-多列布局

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...