题目

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. 八十二、SAP中的ALV创建之一,新建一个程序

    一.创建一个ALV的程序 二.填写程序属性 三.保存到本地对象 四.来到代码区,这样一个新工程就创建好了,我们后续来写相关的创建代码

  2. Ubuntu14.04 无法关机 SpamAssassin speech-dispatcher

    在ubuntu14.04上安装完一些包后,关闭计算机就会出现关于标题中的两个错误. 1.在软件中心卸载spamAssassin 2.运行命令: sudo update-rc.d -f speech-d ...

  3. Delphi MD5

    unit uMD5; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics; type MD5Count = ...

  4. 配置mysql时报错

    配置mysql时无法启动此程序,因为计算机丢失MSVCR100.dll. 去https://cn.dll-files.com/下载相应的版本 复制MSVCR100.dll 粘贴到下面 32位系统: 复 ...

  5. 吴裕雄--天生自然C++语言学习笔记:C++ 标准库

    C++ 标准库可以分为两部分: 标准函数库: 这个库是由通用的.独立的.不属于任何类的函数组成的.函数库继承自 C 语言. 面向对象类库: 这个库是类及其相关函数的集合. C++ 标准库包含了所有的 ...

  6. yum 安装 Mysql error ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 开启远程连接 修改登入密码 忘记root密码 配置防火墙规则 随手mark

    yum 安装 MYsql:        yum install mysql mysql-server mysql-devel -y 1.1 登入报错: ERROR 1045 (28000): Acc ...

  7. buildroot经验

    1.可以运行bulilroot下面的孙可编写的build.sh文件,自动配置和编译 2.如何添加要下载和编译的包? 如要下载和编译libevent, 可以通过make menuconfig, 然后搜索 ...

  8. cnblogs今天挂了

    刚打算搬进来常驻cnblogs,好死不死,它今天11点40分左右挂了.真是不让人省心: 今天把这后面这几个月的随笔放过来,希望能不会被清掉:

  9. 前台图片Canvas压缩上传小结

    需求来源:之前有个提交审核表单的业务,表单中含有大量附件图片,大约有20多张吧,为了省事,采用的同步上传,一次需要上传很多照片,本来单张图片限制为200KB,这样子总图片大小约为5MB左右,想想也可以 ...

  10. maven的理解和使用

    一.maven是什么? maven是项目管理工具 二.maven为什么要用? 在做开发的时候常常会用到外部的工具包(jar包),这就需要你一个一个的去他们的官网下工具包,然后在项目里依赖他们,比较的麻 ...