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 ...
随机推荐
- 某网站的videojs的配置及操作
某网站的videojs的配置及操作 一.总结 一句话总结: 多参照参照别人的例子就好,省事 1.videojs如何获取用户当前视频的位置? this.currentTime() 2.回到视频开始处? ...
- mybatis3.0-[topic10-14] -全局配置文件_plugins插件简介/ typeHandlers_类型处理器简介 /enviroments_运行环境 /多数据库支持/mappers_sql映射注册
mybatis3.0-全局配置文件_ 下面为中文官网解释 全局配置文件的标签需要按如下定义的顺序: <!ELEMENT configuration (properties?, setting ...
- POJ 2155 Matrix[树状数组+差分]
原题链接:https://vjudge.net/problem/POJ-2155 题目大意 给定 n* n 矩阵A,其元素为0或1. A [i][j] 表示第i行和第j列中的数字.最初全为0. 我们有 ...
- 《The one!》团队作业五:团队项目需求改进与系统设计
项目 内容 作业所属课程 所属课程 作业要求 作业要求 团队名称 < The One !> 作业学习目标 (1)掌握面向对象需求分析方法:(2)学习软件系统总体结构和数据库逻辑结构设计,学 ...
- vue 传入一个对象的所有属性
- 原生JS实现简易随机点名功能
定时器的工作原理,这里将用引用How JavaScript Timers Work中的例子来解释定时器的工作原理,该图为一个简单版的原理图.· 上图中,左侧数字代表时间,单位毫秒:左侧文字代表某一个操 ...
- asp.net文件夹上传源码
ASP.NET上传文件用FileUpLoad就可以,但是对文件夹的操作却不能用FileUpLoad来实现. 下面这个示例便是使用ASP.NET来实现上传文件夹并对文件夹进行压缩以及解压. ASP.NE ...
- Python之yield语法
生成器与yield 函数使用yield关键字可以定义生成器对象.生成器是一个函数.它生成一个值的序列,以便在迭代中使用,例如: def countdown(n): print('倒计时:%s' % n ...
- 51nod 3 * problem
1640题意:一张无向图在最小化最大边后求最大边权和 Slove:sort 最小生成树倒叙最大生成树 #include <iostream> #include <cstdio> ...
- Bzoj 3122 [Sdoi2013]随机数生成器(BSGS+exgcd)
Input 输入含有多组数据,第一行一个正整数T,表示这个测试点内的数据组数. 接下来T行,每行有五个整数p,a,b,X1,t,表示一组数据.保证X1和t都是合法的页码. 注意:P一定为质数 Outp ...