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 ...
随机推荐
- BCB 如何让Application收到SendMessage发送来的消息
一般,都是通过添加一个ApplicationEvent组件就可以接收到PostMessage发来的消息,那么如何收到SendMessage发来的消息呢? https://stackoverflow.c ...
- MyBatis 3.0_[tp-24-25]_映射文件_参数处理_#与$取值区别_#{}更丰富的用法
笔记要点出错分析与总结 /**================Mybatis参数值的获取:#和$符号的区别=============== * #{}:可以获得map中的值或者pojo对象属性的值; * ...
- 如何使用Jmeter批量构造MySQL测试数据
前言: 当我们进行API测试.Web Service或者其他系统模块测试时,你可能需要从数据库获取并记录数据.这些测试的目的是检查数据库中指定的数据,或者向数据库添加指定的数据,这篇文章会展示使用JM ...
- centos下shell脚本kill掉mysql锁表进程【笔记】
前几天发现服务器上的mysql出现锁表了,show processlist后发现好多都是因为写进session才锁表的,看到这个想起了会不会是硬盘空间不够了,马上查看了服务器硬盘空间,发现都100%了 ...
- 基于pg_qualstats和hypopg的自动索引调优
pg-qualstats的安装和配置 1.安装pg-qualstats -pg-qualstats 2.将pg_qualstats和pg_stat_statements添加到shared_preloa ...
- h5格式化微信 nickname 保留第一个字,其余用*显示
截取微信nickname中需要注意的是,表情符号和特殊字符,如果你不用正则过滤掉的话,使用slice(0,1)直接截取第一个字符串是不行的,因为表情符号占用两个字节,截取一半,ios会报错,andro ...
- sql 索引的使用 转载:https://www.cnblogs.com/xiaoyangjia/p/11267191.html#mysql_performance
B-Tree索引的3个限制: 如果不是按照索引的最左列开始查找,则无法使用索引 不能跳过索引中的列.如果联合索引(a,b,c) ,如果使用条件a和c条件查询,那么只能使用索引的第一列a 如果查询中有某 ...
- HttpServletRequest获取浏览器、服务端和客户端信息
如何通过HttpServletRequest来获取到上面的属性呢? 1.引入开源工具 <!-- https://mvnrepository.com/artifact/eu.bitwalker/U ...
- spring-定时任务<task:scheduled-tasks>
Spring内部有一个task是Spring自带的一个设定时间自动任务调度,提供了两种方式进行配置,一种是注解的方式,而另外一种就是XML配置方式了.注解方式比较简洁,XML配置方式相对而言有些繁琐, ...
- Python3对时间模块的操作
python中使用time和datetime来进行时间操作 import time import datetime # 获取时间戳 time.time() # 1544601181.549864 # ...