pat甲级题目,-【PAT甲级真题】- Be Unique(20) - Sample Input 2:
题目来源
Be Unique (20) - PTA Be Unique (20) - 牛客
Description
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
,
10
4
]
[1, 10^4]
[1,104]. The first one who bets on a unique number wins. For example, if there are 7 people betting on
{
\{
{
5
5
5
31
31
31
5
5
5
88
88
88
67
67
67 拼多多帮助力入口
88
88
88
17
17
17
}
\}
}, then the second one who bets on
31
31
31 wins.
Input Specification:
Each input file contains one test case. Each case contains a line which begins with a positive integer
N
(
<
=
10
5
)
N (<=10^5)
N(<=105) and then followed by
N
N
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
题目大意
给出一系列数,输出其中第一个只出现一次的数
思路简介
维护一个哈希表或者桶计数即可 我在此处使用的是桶
遇到的问题
无,一遍过
代码
/**
* Be Unique
* https://www.nowcoder.com/pat/5/problem/4080
* https://pintia.cn/problem-sets/994805342720868352/exam/problems/type/7?problemSetProblemId=994805444361437184
* 哈希表判重
*/
#include
using namespace std;
const int N=1e5+7;
int a[N],c[N];
void solve(){
int n;cin>>n;
for(int i=0;i>a[i],c[a[i]]++;
for(int i=0;i
if(c[a[i]]==1){cout<
cout<<"None\n";
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//fstream in("in.txt",ios::in);cin.rdbuf(in.rdbuf());
int T=1;
//cin>>T;
while(T--){
solve();
}
return 0;
}