题目链接: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)的更多相关文章

  1. 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 ...

  2. PAT 甲级 1041 Be Unique (20 分)(简单,一遍过)

    1041 Be Unique (20 分)   Being unique is so important to people on Mars that even their lottery is de ...

  3. PAT 甲级 1041. Be Unique (20) 【STL】

    题目链接 https://www.patest.cn/contests/pat-a-practise/1041 思路 可以用 map 标记 每个数字的出现次数 然后最后再 遍历一遍 找到那个 第一个 ...

  4. 【PAT甲级】1041 Be Unique (20 分)(多重集)

    题意: 输入一个正整数N(<=1e5),接下来输入N个正整数.输出第一个独特的数(N个数中没有第二个和他相等的),如果没有这样的数就输出"None". AAAAAccepte ...

  5. 【PAT】1004. 成绩排名 (20)

    1004. 成绩排名 (20) 读入n名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. 输入格式:每个测试输入包含1个测试用例,格式为 第1行:正整数n 第2行:第1个学生的姓名 ...

  6. 【PAT】1019 数字黑洞 (20)(20 分)

    1019 数字黑洞 (20)(20 分) 给定任一个各位数字不完全相同的4位正整数,如果我们先把4个数字按非递增排序,再按非递减排序,然后用第1个数字减第2个数字,将得到一个新的数字.一直重复这样做, ...

  7. 【PAT】1013. 数素数 (20)

    1013. 数素数 (20) 令Pi表示第i个素数.现任给两个正整数M <= N <= 104,请输出PM到PN的所有素数. 输入格式: 输入在一行中给出M和N,其间以空格分隔. 输出格式 ...

  8. 【PAT】1012. 数字分类 (20)

    1012. 数字分类 (20) 给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算 ...

  9. 【PAT】1009. 说反话 (20)

    1009. 说反话 (20) 给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出. 输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串.字符串由若干单词和若干空格组成,其 ...

随机推荐

  1. qnx:从API开始理解QNX -- 消息传递

    从API开始理解QNX -- 消息传递    http://www.openqnx.com/chinese/viewtopic.php?f=5&t=2161 1. 频道与连接    Chann ...

  2. poj 1604 Just the Facts

    /** 大意: 求n! 结果 从左到右 第一个非零数 跟 1150 差不多.. **/ #include <iostream> #include <cstdio> using ...

  3. 腾讯地图之Marker

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  4. Linux下gsoap实现webservice功能

    蓝字为关键字,等号=后面为关键字值. 一.介绍 我们用的webservice是根据gsoap编译工具来实现,gSOAP的编译器能够自动的将用户定义的本地化的C或C++数据类型转变为符合XML语法的数据 ...

  5. Hadoop Hive与Hbase整合+thrift

    Hadoop Hive与Hbase整合+thrift 1.  简介 Hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供完整的sql查询功能,可以将sql语句 ...

  6. Muduo 网络编程示例之零:前言

    陈硕 (giantchen_AT_gmail)Blog.csdn.net/Solstice Muduo 全系列文章列表: http://blog.csdn.net/Solstice/category/ ...

  7. linux下观看b站视频,解决字体乱码

    如图: 各种字体都显示为方块,解决办法也很简单. 点击视频右边的齿轮,也就是设置,更改字体. 默认的微软雅黑字体,一般换成其他的字体应该都能正常显示. 这是为更改后:

  8. hdu 1232 畅通project

    题目: 链接:点击打开链接 算法: 赤裸裸的并查集. 代码: #include<iostream> #include<cstdio> #include<cstring&g ...

  9. JS - 删除确认

    <a href="javascript:if(confirm('确实要删除吗?'))location='<{:U('Admin/Update/deleteuserinfo', a ...

  10. 【前端】CSS雪碧

    百度百科:http://baike.baidu.com/link?url=jblMCCF77bq7egbJ-9SudRmvXdwlQVVOq5D9MEEniQgJR-Lqanfrnjzwmgu7ato ...