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来存储原来的输入顺序这个是需要的。
最新文章
- UITableViewCell内放置复杂结构的subview,但subview中的Button不响应点击事件
- Oracle数据库导入导出命令总结 (详询请加qq:2085920154)
- ElasticSearch部署
- 多层级Spinner列表选项实时更新树形层级(选择城市)
- oracle11g创建数据库最后一步确定时弹出无法创建目录
- PAT L1-009. N个数求和
- C# aspnetpager分页
- Heritrix源码分析(十五)
- windows下 sbulime text 安装less2css踩的几个坑
- nodejs 使用CAS 实现 单点登录(SSO) 【开源库实现,简单】
- 定时删除所有文件夹下的_desktop.ini文件
- dvi文件和将dvi文件转换成pdf格式
- Js 框架之Vue .JS学习记录 ① 与Vue 初识
- [CF977F]Consecutive Subsequence
- Xtrabackup的安装
- Unity3D笔记十六 输入输出-键盘事件、鼠标事件
- maven随笔
- Gym 101246D	Fire in the Country(dfs求SG函数)
- 腾讯云 服务器 ubuntu 16.04 python3 环境
- DotNetOpenAuth实践之Windows签名制作