【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的字符串.字符串由若干单词和若干空格组成,其 ...
随机推荐
- easyui好例子,值得借鉴
http://www.cnblogs.com/wuhuacong/p/3317223.html
- selenium+BeautifulSoup+phantomjs爬取新浪新闻
一 下载phantomjs,把phantomjs.exe的文件路径加到环境变量中,也可以phantomjs.exe拷贝到一个已存在的环境变量路径中,比如我用的anaconda,我把phantomjs. ...
- java.util.concurrent BlockingQueue
BlockingQueue 它实现了Queue接口.它是A BlockingQueue with one thread putting into it, and another thread taki ...
- linux小命令
本文主要记录了我在工作中用到的一些linux命令 1.查询linux系统是32位还是64位 zhaolei@zhaolei :~# file /usr/bin/whoami/usr/bin/whoam ...
- 自定义类StyleSheet跨浏览器操作样式表中的规则
这是群里网友地瓜提供的一个类,不熟悉样式表对象和样式规则对象的浏览器差异的可以看看 /** * Stylesheet.js: utility methods for scripting CSS sty ...
- QT学习 之 对话框 (四) 字体对话框、消息对话框、文件对话框、进程对话框(超详细中文注释)
QMessageBox类: 含有Question消息框.Information消息框.Warning消息框和Critical消息框等 通常有两种方式可以来创建标准消息对话框: 一种是采用“基于属性”的 ...
- HNOI2016 网络
题目 朴素算法 在线. 树链剖分套一个堆. 时间复杂度\(O(n (\log n)^3)\). 分治 朴素算法中,套一个堆是为了支持删除操作. 采用以下分治可以避免删除操作: 每次对时间\([l,r] ...
- IT第二十天 - 面向对象编程思想、抽象类、异常处理、程序操作日志记录、本周总结 ★★★
IT第二十天 上午 面向对象编程思想 1.组装电脑的设计: (1)电脑的组成:显示器+机箱 (2)机箱的组成:电源+主板+硬盘 (3)主板所包含的部件:cpu+内存+PCI接口+usb接口 (4)PC ...
- Lua,Lua API,配置文件
想像一个场景:你的c程序须要有一个窗体,你想让用户能够自己定义窗体大小.方法非常多.比方使用环境变量,或键值对的文件. 无论如何,你须要解析它. 使用lua配置文件是个不错的选择. 首先,你能够定义例 ...
- android代码实现关机
1.API没有开放,需要提升为syetem app级别! 2.android 模块编译,mm 命令 2.1.先进入顶层 source build/envsetup.sh 2.2.进入目录 m ...