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来存储原来的输入顺序这个是需要的。

PAT 1041 Be Unique[简单]的更多相关文章

  1. pat 1041 Be Unique(20 分)

    1041 Be Unique(20 分) Being unique is so important to people on Mars that even their lottery is desig ...

  2. PAT 1041 Be Unique (20分)利用数组找出只出现一次的数字

    题目 Being unique is so important to people on Mars that even their lottery is designed in a unique wa ...

  3. PAT 甲级 1041 Be Unique (20 分)(简单,一遍过)

    1041 Be Unique (20 分)   Being unique is so important to people on Mars that even their lottery is de ...

  4. 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 ...

  5. PAT 甲级 1041 Be Unique (20 分)

    1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is desi ...

  6. 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 ...

  7. PAT甲级——1041 Be Unique

    1041 Be Unique Being unique is so important to people on Mars that even their lottery is designed in ...

  8. 1041 Be Unique (20 分)

    1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is desi ...

  9. 【PAT】1041. Be Unique (20)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1041 题目描述: Being unique is so important to people ...

随机推荐

  1. NAT and Traversal NAT(TURN/STUN/ICE)

    http://www.cnblogs.com/whyandinside/archive/2010/12/08/1900492.html -------------------------------- ...

  2. CSS3制作文字半透明倒影效果

      效果如图.Ps.背景线条是背景图勒,和本文效果无关... html代码如下: <div class="content"> <h3 title="专业 ...

  3. multimap 小例子

    场景: 按DDX值倒序取前十的板块代码,用 map<float, string, greater<float> > mapBKDDX; 存储时,相同DDX值的板块只能存储第一个 ...

  4. java--Struts中请求的过程

    一个请求在Struts2框架中的处理步骤: a) 客户端初始化一个指向Servlet容器的请求: b) 根据Web.xml配置,请求首先经过ActionContextCleanUp过滤器,其为可选过滤 ...

  5. oracle和SQLserver数据库中select into 的区别

    在Oracle中是这样的 在SQLserver中是这样的

  6. PPT如何一页多张打印且铺满整个页面

    最近由于工作需要,有些ppt材料想打印出来学习,但是ppt页数较多,ppt单页打印有些浪费纸张,而且也不能拿到外面打印店去打印,所以只能自己动手设置一页多张打印,并且最后双面打印,这样就做够节省纸张了 ...

  7. iOS -转载-根据字母排序

    1.从小到大自然排序NSDictionary *dic = @{", ", ", ", ", ", ", ", &quo ...

  8. 在scrollview中双击定点放大的代码

    双击放大是 iPhone 的一个基本操作,第三方程序里引入这一功能的话,主要是在 scrollview 呈现一张图片或者 PDF 页面时,双击可以放大,主要代码如下 - (void)scrollVie ...

  9. 【BZOJ3417】Poi2013 Tales of seafaring 分层图BFS

    [BZOJ3417]Poi2013 Tales of seafaring Description 一个n点m边无向图,边权均为1,有k个询问 每次询问给出(s,t,d),要求回答是否存在一条从s到t的 ...

  10. Sharepoint ECMAScript

    前言 本文完全原创,转载请说明出处,希望对大家有用. 本篇博客是个人总结,一方面以便日后查看,另一方面希望能为其他人提供一些便利. 阅读目录 加载必要文件 (Get,Update,Delete,Add ...