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,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

题目大意:给出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来存储原来的输入顺序这个是需要的。

最新文章

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

热门文章

  1. C++ c++与C语言的区别(空结构体)
  2. The Properties of Posterior of Topic Model
  3. orm工具的基本思想
  4. Android SDK代理server解决国内不能更新下载问题
  5. HTML邮件注意事项(转)
  6. JavaScript学习系列之内存模型篇
  7. 《linux系统及其编程》实验课记录(四)
  8. 关于Animator状态在运行时的正负方向播放
  9. SVN入门 服务器VisualSVN Server和客户端TortoiseSVN安装
  10. 2D绘图引擎比较