PAT Advanced 1041 Be Unique (20) [Hash散列]
题目
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
题目分析
已知一系列数,找到第一个不重复的数字
解题思路
- 定义数组ns[N],存放输入数字
- 定义数组ts[10001],记录输入数字出现次数
- 大小为10001,(题目已知:输入数字取值范围[1, 10^4])
- 数组下标--输入数字
- 数组元素--输入数字出现次数
- 遍历输入数字(ns数组),最早出现次数==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散列]的更多相关文章
- 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 ...
- 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 ...
- 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. ...
- PAT Advanced 1048 Find Coins (25) [Hash散列]
题目 Eva loves to collect coins from all over the universe, including some other planets like Mars. On ...
- 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 ...
- PAT Basic 1047 编程团体赛(20) [Hash散列]
题目 编程团体赛的规则为:每个参赛队由若⼲队员组成:所有队员独⽴⽐赛:参赛队的成绩为所有队员的成绩和:成绩最⾼的队获胜.现给定所有队员的⽐赛成绩,请你编写程序找出冠军队. 输⼊格式: 输⼊第⼀⾏给出⼀ ...
- 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 ...
- PAT 甲级 1041 Be Unique (20 分)(简单,一遍过)
1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is de ...
- 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 ...
随机推荐
- kibana下载与安装
目录 简介 下载 安装 测试 简介 Kibana是一个为ElasticSearch 提供的数据分析的 Web 接口.可使用它对日志进行高效的搜索.可视化.分析等各种操作.安装之前有话说: 安装路径不要 ...
- Day 21:网络编程(2)
以课程中feiQ为例,feiQ作为一个典型的网络编程应用,用一段代码尝试给自己的发送消息 import java.io.IOException; import java.net.DatagramPac ...
- iOS 13适配
1. 安装时,加入Xcode11.3 后 原xcode会安装开发工具插件时候出现 点击安装插件之后会出现 目前没找到解决方案.只能在一个mac电脑上安装使用一个版本. 2.编译时,会出现libstdc ...
- 洛谷 P2697 宝石串
题目传送门 解题思路: 将红色的设置为-1,绿色的为1,统计前缀和sum,如果sum[i] == sum[j],则说明i~j是一个稳定的区间 因为答案要求最大,所以我们要记录每个sum值的最左端点(也 ...
- CSS - 导入Google Web 字体
@import url('http://fonts.googleapis.com/css?family=Poppins:100,200,300,400,500,600,700,800,900'); b ...
- PHP上传图片,路径保存在数据库中,根据图片路径显示图片
1.创建数据表 CREATE TABLE image( id int(4) unsigned NOT NULL AUTO_INCREMENT, name varchar(100) default ...
- 大数据高可用集群环境安装与配置(09)——安装Spark高可用集群
1. 获取spark下载链接 登录官网:http://spark.apache.org/downloads.html 选择要下载的版本 2. 执行命令下载并安装 cd /usr/local/src/ ...
- IntelliJ IDEA ULTIMATE 2019.3 破解注册详细教程【亲测有效,持续更新~】
申明:本教程 IntelliJ IDEA 破解补丁.激活码均收集于网络,请勿商用,仅供个人学习使用,如有侵权,请联系作者删除. 注意 本教程适用于 IntelliJ IDEA 所有版本,请放心食用 ...
- AP架构基本过程
①.有线网络搭建(vlan,dhcp,路由等.) ②.ap零配置启动,通过dhcp获取IP地址及网关ip,同时获取ac ip地址. ③.AP主动建立到达ac的capwap隧道. ④.ap与ac建议隧道 ...
- SublimeText3和插件的安装
SublimeText3和插件的安装 步骤一:进入官网下载SublimeText3(http://www.sublimetext.com/3),安装并打开SublimeText3 步骤二:进入Su ...