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 ...
随机推荐
- C++ 函数的扩展①
//函数扩展--内联函数 inline #include<iostream> using namespace std; /* c++中const常量可以替代宏常数定义 如: const i ...
- java 多线程 3 synchronized 同步
多任务编程的难点在于多任务共享资源.对于同一个进程空间中的多个线程来说,它们都共享堆中的对象.某个线程对对象的操作,将影响到其它的线程. 在多线程编程中,要尽力避免竞争条件(racing condit ...
- "reason":"No handler for type [attachment] declared on field [file]" 最完全解决方案
0.elasticsearch-mapper-attachments 2.3.4安装 mapper-attachments安装方法分两类,在线和离线: 在线安装 bin/elasticsearch-p ...
- Python使用pycurl获取http的响应时间
最近需要对节点到源站自己做个监控,简单的ping可以检测到一些东西,但是http请求的检查也要进行,于是就研究了下pycurlpycurl是个用c语言实现的python 库,虽然据说不是那么pytho ...
- C# 导出Excel "正在中止线程" 错误
导出Excel相信很多人都用过,但是我却遇到了一个问题 “正在中止线程” 源代码如下: public static void ExportExcel(string fileName, GridView ...
- malloc free, new delete 的异同点
相同点: 都可以动态的申请并释放内存 不同点: 1. 用法不同 <1> malloc 函数为 void* malloc(size_t size), 用于申请一块长度为 size 字节的内存 ...
- instance method '*****' not found (return type defaults to 'id')
博文转载至 http://blog.csdn.net/cerastes/article/details/38025801 return type defaultsnot foundiOSwarning ...
- C/C++ 智能指针简单剖析
导读 最近在补看<C++ Primer Plus>第六版,这的确是本好书,其中关于智能指针的章节解析的非常清晰,一解我以前的多处困惑.C++面试过程中,很多面试官都喜欢问智能指针相关的问题 ...
- Surface UEFI 菜单显示
下载 Surface 的恢复映像 https://support.microsoft.com/zh-cn/surfacerecoveryimage UEFI 设置只能在系统启动时进行调整.若要加载 ...
- spring-boot Web集群
SpringBoot启动类增加注解 @EnableRedisHttpSession @SpringBootApplication @ImportResource({"classpath:co ...