PAT 1041 Be Unique[简单]
1041 Be Unique (20 分)
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
题目大意:给出n个数,判断其中不重复出现的第一个数,如果均是重复出现,那么就输出None.
//还是比较简单的。AC了:
#include <iostream>
#include <vector>
#include<unordered_map>
using namespace std; int main()
{
int n,ans=-;
cin>>n;
unordered_map<int,int> mp;
vector<int> vt;
int key;
for(int i=;i<n;i++){
cin>>key;
vt.push_back(key);
if(mp[key]==)
mp[key]=-;
else
mp[key]=;
}
for(int i=;i<vt.size();i++){
if(mp[vt[i]]==-){
ans=vt[i];break;
}
}
if(ans==-)
cout<<"None";
else
cout<<ans; return();
}
1.其实可以不使用unorder_map的,它并不是按输入顺序排序,而是随机的吧,可以使用map
2.既然要记录顺序,那么就使用vector来存储原来的输入顺序这个是需要的。
PAT 1041 Be Unique[简单]的更多相关文章
- pat 1041 Be Unique(20 分)
1041 Be Unique(20 分) Being unique is so important to people on Mars that even their lottery is desig ...
- PAT 1041 Be Unique (20分)利用数组找出只出现一次的数字
题目 Being unique is so important to people on Mars that even their lottery is designed in a unique wa ...
- 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 Level) Practice 1041 Be Unique (20 分) 凌宸1642
PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642 题目描述: Being unique is so important to peo ...
- PAT 甲级 1041 Be Unique (20 分)
1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is desi ...
- 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
1041 Be Unique Being unique is so important to people on Mars that even their lottery is designed in ...
- 1041 Be Unique (20 分)
1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is desi ...
- 【PAT】1041. Be Unique (20)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1041 题目描述: Being unique is so important to people ...
随机推荐
- Linux - 静默安装oracle数据库总结
Web服务器上面的Linux一般是不会有图形界面的,所有通过图形界面来安装Linux的方式在没有图形界面的Linux上面是行不通的,我们要使用的安装方式叫做Linux的静默安装.即在没有图形界面的Li ...
- SQL Server,MySql,Oracle数据库的默认端口号
SQL Server默认端口号为:1433 MySQL 默认端口号为:3306 Oracle 默认端口号为:1521
- 24SpringMvc中的重定向和转发-解释return "redirect:/cargo/contractproduct/tocreate.action";
我在做JK项目时发现:我们在增加一个货物时.会先根据提交的Action()进入到一个新增页面 //跳转到新增的页面 @RequestMapping("/cargo/contractprodu ...
- 程序生成word与PDF文档的方法(python)
程序导出word文档的方法 将web/html内容导出为world文档,再java中有很多解决方案,比如使用Jacob.Apache POI.Java2Word.iText等各种方式,以及使用free ...
- ThinkPHP整合cropper剪裁图片上传功能
1.先下载核心文件:https://github.com/fengyuanchen/cropper 2. 3.对于index.html文件 4.对于main.js文件 5.对于crop.php文件 & ...
- Linux命令在线中文手册
很好的Linux学习手册:http://linux.51yip.com/ 来源:http://blog.51yip.com/
- Android中BroadcastReceiver组件具体解释
Android系统的4个组件最终还剩一种组件了BroadcastReceiver,这个组件是全局监听器,能够监听系统全局的广播消息,能够方便的实现系统中不同组件之间的通信 BroadcastRecei ...
- 【mysql】windows7 安装 Mysql
From: http://jingyan.baidu.com/article/e52e3615a1128c40c70c5174.html 安装(解压) ZIP Archive版是免安装的.只要解压就行 ...
- 【Debian】ftp安装
http://www.2cto.com/os/201107/98311.html http://jingyan.baidu.com/article/adc815133476bdf723bf7393.h ...
- log4net写txt日志
1.配置: <configSections>节点下添加: <section name="log4net" type="log4net.Config.Lo ...