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]. 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 (≤) 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.

题解:

用类似打表的方法,统计每个数出现的次数。按输出顺序遍历,当有次数为1的数时,输出,没有就输出None。

AC代码:

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cstring>
using namespace std;
int a[];
int shu[];
int main()
{
int n;
cin>>n;
memset(a,,sizeof(a));
for(int i=;i<=n;i++){
cin>>shu[i];
a[shu[i]]++;
}
int f=;
for(int i=;i<=n;i++){
if(a[shu[i]]==){
cout<<shu[i];
f=;
break;
}
}
if(!f) cout<<"None";
return ;
}

PAT 甲级 1041 Be Unique (20 分)(简单,一遍过)的更多相关文章

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

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

  2. PAT Advanced 1041 Be Unique (20 分)

    Being unique is so important to people on Mars that even their lottery is designed in a unique way. ...

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

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

  5. PAT 甲级 1041 Be Unique (20 分)

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

  6. PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)

    1050 String Subtraction (20 分)   Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be t ...

  7. PAT 甲级 1042 Shuffling Machine (20 分)(简单题)

    1042 Shuffling Machine (20 分)   Shuffling is a procedure used to randomize a deck of playing cards. ...

  8. PAT 甲级 1035 Password (20 分)

    1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...

  9. PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)

    1073 Scientific Notation (20 分)   Scientific notation is the way that scientists easily handle very ...

随机推荐

  1. Dos命令获取当前时间

    = = 这个真的折腾死我了.... 参考:http://bbs.bathome.net/thread-3328-1-1.html 操作系统不同,日期格式也可能不同: 星期二 2008-07-29 20 ...

  2. 前端处理:elementUI 表格索引代表第几条数据

    分析:表格结合分页 知识点:1.表格的自定义索引(索引以当前行的行号作为参数)number, Function(index)该属性传入数字时,将作为索引的起始值.也可以传入一个方法,它提供当前行的行号 ...

  3. matlab(2) Logistic Regression: 画出样本数据点plotData

    画出data数据 data数据 34.62365962451697,78.0246928153624,030.28671076822607,43.89499752400101,035.84740876 ...

  4. vue2 自定义键盘事件

  5. 第113题:路径总和II

    一. 问题描述 给定一个二叉树和一个目标和,找到所有从根节点到叶子节点路径总和等于给定目标和的路径. 说明: 叶子节点是指没有子节点的节点. 示例: 给定如下二叉树,以及目标和 sum = 22, 5 ...

  6. Java:JVM垃圾回收(GC)机制

    JVM垃圾回收算法 1.标记清除(Mark-Sweep) 原理: 从根集合节点进行扫描,标记出所有的存活对象,最后扫描整个内存空间并清除没有标记的对象(即死亡对象)适用场合: 存活对象较多的情况下比较 ...

  7. blind XXE payload

    简单验证 POST /test HTTP/1.1 Content-Type: application/soap+xml User-Agent: scanner Accept: */* Cache-Co ...

  8. 获取历史K线数据的几个方法

    1.通过已有的股票交易软件下载数据,如果他们是开源结构的,就可以解析他们的K线数据. 2.在互联网上抓取数据 int iStockCode;CString strUrl; 通过OpenUrl.Read ...

  9. PHP 函数运行的内存

    函数在运行期间占用的内存,在运行结束后会被回收.但是还有问题不明白,函数内部的echo在函数执行结束后还占用内存吗??? //PHP 函数执行完内存就会被收回 function test() { ec ...

  10. MongoDB存储引擎、索引 原

    wiredTiger MongoDB从3.0开始引入可插拔存储引擎的概念.目前主要有MMAPV1.WiredTiger存储引擎可供选择.在3.2版本之前MMAPV1是默认的存储引擎,其采用linux操 ...