【PAT】1041. Be Unique (20)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1041
题目描述:
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
分析:(1)直接用查询表。(2)有个坑爹的陷阱,用cin输入会超时,但是用scanf输入去可以通过。原因是???
参考代码:
#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
int result[10000 + 5];
int input[100000 + 5];
int main()
{
int n;
cin>>n;
int i;
int temp;
bool flag = false; for(i=0; i<n; i++)
{
//cin>>input[i]; 用cin会超时, 用scanf不会
scanf("%d",&input[i]);
result[ input[i] ]++;
} for(i=0; i<n; i++)
{
if(result[ input[i] ] == 1)
{
flag = true;
break;
}
}
if(flag)
cout<<input[i]<<endl; else
cout<<"None"<<endl;
return 0;
}
【PAT】1041. Be Unique (20)的更多相关文章
- 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 (20 分)(简单,一遍过)
1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is de ...
- PAT 甲级 1041. Be Unique (20) 【STL】
题目链接 https://www.patest.cn/contests/pat-a-practise/1041 思路 可以用 map 标记 每个数字的出现次数 然后最后再 遍历一遍 找到那个 第一个 ...
- 【PAT甲级】1041 Be Unique (20 分)(多重集)
题意: 输入一个正整数N(<=1e5),接下来输入N个正整数.输出第一个独特的数(N个数中没有第二个和他相等的),如果没有这样的数就输出"None". AAAAAccepte ...
- 【PAT】1004. 成绩排名 (20)
1004. 成绩排名 (20) 读入n名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. 输入格式:每个测试输入包含1个测试用例,格式为 第1行:正整数n 第2行:第1个学生的姓名 ...
- 【PAT】1019 数字黑洞 (20)(20 分)
1019 数字黑洞 (20)(20 分) 给定任一个各位数字不完全相同的4位正整数,如果我们先把4个数字按非递增排序,再按非递减排序,然后用第1个数字减第2个数字,将得到一个新的数字.一直重复这样做, ...
- 【PAT】1013. 数素数 (20)
1013. 数素数 (20) 令Pi表示第i个素数.现任给两个正整数M <= N <= 104,请输出PM到PN的所有素数. 输入格式: 输入在一行中给出M和N,其间以空格分隔. 输出格式 ...
- 【PAT】1012. 数字分类 (20)
1012. 数字分类 (20) 给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算 ...
- 【PAT】1009. 说反话 (20)
1009. 说反话 (20) 给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出. 输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串.字符串由若干单词和若干空格组成,其 ...
随机推荐
- char*与char[]
char *s1="hello"; // 指向常量区 char s2[]="hello"; // 指向数组的内存空间 char *s1 的s1是指针,指 ...
- win7如何快速设置开机启动项?
添加开机启动项方法: 找到windows开始菜单->所有程序->启动,右键打开, 进入C:\Users\Ocean\AppData\Roaming\Microsoft\Windows\St ...
- fieldset效果
<form> <fieldset> <legend>健康信息</legend> 身高:<input type="text" / ...
- uoj #2 【NOI2014】起床困难综合症 贪心+位运算
题目链接 给出n个数, 每个数有特定的一种操作, &|^三种, 给出一个m, 初始值属于[0,m],选定一个初始值, 使所有操作做完之后的值最大, 输出这个最大值. 1, 从最高位贪心, 如果 ...
- 解决Sublime Text3莫名的中文乱码问题
有好几回用Sublime Text3写着中英混杂的文字的时候,会突然就弹出警告说什么编码不行,然后点击确定后,原来的中文全都乱码了: 然后即使按ctrl+z撤回也没用,重新打开也没用,用记事本的转换a ...
- hdu 4790 Just Random 神奇的容斥原理
/** 大意: 给定[a,b],[c,d] 在这两个区间内分别取一个x,y 使得 (x+y)%p = m 思路:res = f(b,d) -f(b,c-1)-f(a-1,d)+f(a-1,c-1); ...
- sql差异
类别 MS SQL Server My SQL PG SQL Oracle Access 自增 identity(1,1) auto_increment ALTER TABLE 'tableNam ...
- UVA 103 Stacking Boxes (dp + DAG上的最长路径 + 记忆化搜索)
Stacking Boxes Background Some concepts in Mathematics and Computer Science are simple in one or t ...
- 学习OpenBlas
编译 从OpenBlas Home Page 上下载源代码.make, make install 使用 level 1 向量-向量 操作 #include <iostream> #incl ...
- 怎样让jQuery和其它js库共存
怎样让jQuery和其它js库共存 有时候需要同时使用jQuery和其它javascript,比如在joomla中默认的是motools,但很多人还是希 望能够使用jQuery,如果直接调用的话,由于 ...