PAT1041: 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 思路
和1084差不多的思路,队列q记录顺序,字典dic记录是否重复出现。遍历q的时候查下字典,输出第一个满足"仅出现一次"的数字即可。
代码
#include<iostream>
#include<map>
#include<iterator>
#include<queue>
using namespace std;
int main()
{
int N;
while(cin >> N)
{
map<int,int> dic;
queue<int> q;
for(int i = ;i < N;i++)
{
int value;
cin >> value;
if(dic.count(value) > )
dic[value] = -;
else
{
q.push(value);
dic.insert(pair<int,int>(value,));
}
} bool check = false;
while(!q.empty())
{
if(dic[q.front()] > )
{
check = true;
cout << q.front();
break;
}
q.pop();
}
if(!check)
cout << "None" << endl;
}
}
PAT1041: Be Unique的更多相关文章
- PAT-1041 Be Unique
Being unique is so important to people on Mars that even their lottery is designed in a unique way. ...
- pat1041. Be Unique (20)
1041. Be Unique (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Being uniqu ...
- [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- [LeetCode] Minimum Unique Word Abbreviation 最短的独一无二的单词缩写
A string such as "word" contains the following abbreviations: ["word", "1or ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Unique Word Abbreviation 独特的单词缩写
An abbreviation of a word follows the form <first letter><number><last letter>. Be ...
- [LeetCode] Unique Binary Search Trees 独一无二的二叉搜索树
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...
- [LeetCode] Unique Paths II 不同的路径之二
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
随机推荐
- AngularJS进阶(二十四)AngularJS与单选框及多选框的双向动态绑定
AngularJS与单选框及多选框的双向动态绑定 赠人玫瑰,手留余香.若您感觉此篇博文对您有用,请花费2秒时间点个赞,您的鼓励是我不断前进的动力,共勉! AngularJS 在 <in ...
- Android listView异步下载和convertView复用产生的错位问题
1:Item图片显示重复 这个显示重复是指当前行Item显示了之前某行Item的图片. 比如ListView滑动到第2行会异步加载某个图片,但是加载很慢,加载过程中ListView已经滑动到了第14行 ...
- AP INVOICES IMPORT API(NOT request)
PROCEDURE process_cux_to_ap(x_return_status OUT NOCOPY VARCHAR2, x_msg_count OUT NOCOPY NUMBER, x_ms ...
- C#中任意类型数据转成JSON格式
/// <summary> /// List转成json /// </summary> /// <typeparam name="T&quo ...
- vim配置文件(本人喜欢的风格)
在/etc/vimrc这个文件 if v:lang =~ "utf8$" || v:lang =~ "UTF-8$" set fileencodings=utf ...
- LeetCode(46)-Remove Nth Node From End of List
题目: Given a linked list, remove the nth node from the end of list and return its head. For example, ...
- 继续死磕SDRAM控制器
SDRAM控制器 博主上一篇介绍了一些SDRAM的基本原理是否有必要学习使用纯Verilog写一个SDRAM控制器,接下来记录SDRAM控制器的工作原理.首先是上电初始化. 上电初始化 时序图中,tR ...
- 排序算法入门之插入排序(java实现)
插入排序思想:相当于插入元素,对于第i个元素,i之前的元素已经是有序的了,这时候将第i个元素依次与前面元素比较,插入合适的位置.
- SpringBoot集成jsp
一.springBoot集成jsp: 1.修改pom文件 <!--集成jsp所需jar包--> <!--jsp页面使用jstl标签--> <dependency> ...
- mongodb常用语句
一.查询 find方法 db.collection_name.find(); 查询所有的结果: select * from users; db.users.find(); 指定返回那些列(键): se ...