PAT 甲级 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 分)(简单,一遍过)的更多相关文章
- PAT 甲级 1041. Be Unique (20) 【STL】
题目链接 https://www.patest.cn/contests/pat-a-practise/1041 思路 可以用 map 标记 每个数字的出现次数 然后最后再 遍历一遍 找到那个 第一个 ...
- 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. ...
- 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 ...
- 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 desi ...
- PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)
1050 String Subtraction (20 分) Given two strings S1 and S2, S=S1−S2 is defined to be t ...
- PAT 甲级 1042 Shuffling Machine (20 分)(简单题)
1042 Shuffling Machine (20 分) Shuffling is a procedure used to randomize a deck of playing cards. ...
- PAT 甲级 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
- PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
随机推荐
- Python+request 使用pymysql连接数据库mysql的操作《十》
使用指南.pymysql支持python2.7同时也支持python3.x.当前我用的是python2.7.所以过断选择了pymysql的使用,这里注意几点.一般我们连接数据库为了安全起见,都会要求按 ...
- vb开发最全教程
https://www.xin3721.com/eschool/VisualBasicenet/
- JavaScript是如何工作的02:深入V8引擎&编写优化代码的5个技巧
概述 JavaScript引擎是执行 JavaScript 代码的程序或解释器.JavaScript引擎可以实现为标准解释器,或者以某种形式将JavaScript编译为字节码的即时编译器. 以为实现J ...
- Greenplum 函数 gp_dist_random
转载自:https://yq.aliyun.com/articles/7593 函数作用: gp_dist_random('gp_id')本质上就是在所有节点查询gp_id, gp_dist_rand ...
- PHP变量及其操作
一.概念 变量是内存中用于存储数据的一个空间,这个空间有一个名字,这个名字就是变量名,变量名用于对这个内存中的数据进行引用的 二.声明 语法: $变量名=值 变量名只能包含字母.数字.下划线,只 ...
- Chinese Mahjong
OJ题号:UVa11210 思路: 首先字符串处理读入手牌,str数组将手牌和数字对应,接下来搜索,先搜对子,如果搜过对子就不搜了.由于对子有且只有一个,可以在搜到以后直接跳出.同时注意一副麻将中每种 ...
- faebdc的烦恼 莫队
faebdc的烦恼 莫队 题面 思路 有点难想的莫队. 首先我们肯定要一个cnt[i]记录难度i出现的次数,但是我们发现每次删去一个难度后,如果那个难度的个数恰好是当前最多次数,我们就可能要更新一下答 ...
- 04_Logstash安装
Logstash部署 1.部署JDK环境 2.下载Logstash源码包 $ wget https://artifacts.elastic.co/downloads/logstash/logstash ...
- linux系列(十四):head命令
1.命令格式: head [参数] [文件] 2.命令功能: head 用来显示档案的开头至标准输出中,默认head命令打印其相应文件的开头10行. 3.命令参数: -q 隐藏文件名 -v 显示文件名 ...
- CodeForces 787 题解
A题,因为数据范围很小,所以只要暴力即可,如果能相遇一定范围不大,如果范围很大还没相遇一定是不会相遇的了.正解应当是用扩展欧几里得计算这个方程的整数解,再想办法看看有没有正整数解才是. B题,只要看懂 ...