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 ...
随机推荐
- 008Maven_建立私服
参考博客:http://blog.csdn.net/fengspg/article/details/22507737 .1. Maven私服 关于中央仓库注意事项 l 地址: 目前来说: htt ...
- 在J2EE中属于Web层的组件有(选择1项)
在J2EE中属于Web层的组件有(选择1项) A. HTML B. EJB C. Applet D. JSP 解答:D
- Application应用程序级变量
对于每一个网站访问用户都要访问的变量,应该将它设为________变量.(选择1项) A. Session B. Reques C. Response D. Application 解答:D
- 禁止Apache显示目录索引的常见方法
禁止Apache显示目录索引,禁止Apache显示目录结构列表,禁止Apache浏览目录,这是网上提问比较多的,其实都是一个意思.下面说下禁止禁止Apache显示目录索引的常见的3种方法. 要实现禁止 ...
- mysql更改utf8编码方式
方法1: 一.查看数据库编码格式 1 mysql> show variables like 'character_set_database'; 二.查看数据表的编码格式 1 mysql> ...
- 配置使用TargetFrameworks输出多版本类库
1.类库右键 2.修改配置 修改前: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <Targe ...
- C#,C++Dll文件调用心得
C#下: 1.新建-->项目-->控制台应用程序:填写各种名称之后项目新建成功:一下为默认生成方式. 2.如下,在Program.cs中添加如下代码: using System;using ...
- python中的各种符号
在这里所作的是将所有的 Python 符号和关键字列出来,这些都是值得掌握的重点. 关键字 and del from not while as elif global ...
- Linux Centos 开启防火墙 FirewallD is not running
转载自:http://www.z4zr.com/page/1006.html CentOS7用firewall命令“替代”了iptables.在这里我们需要区分“iptables服务”和“iptabl ...
- 进击的RecyclerView入门三(要是能拖动就好了)
还是接着上一讲"进击的RecyclerView入门二(来点小装饰?)",在上一讲中我们学到了怎么给不同的Item定制不同的外观,但貌似那个蓝色的框实在太丑了,咱还是把它干了吧. @ ...