题目描述:
PAT 1041 Be Unique
1041 Be Unique
Input Specification:
Each input file contains one test case. Each case contains a line which begins with a positive integer N (≤10^5) 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
提问:
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
int main(){
int n;
while(scanf("%d",&n)!=EOF){
vector <int> vi;
for(int i=0;i<n;++i){
int tmp;
scanf("%d",&tmp);
if(tmp>=1&&tmp<=pow(10,5)) vi.push_back(tmp);
}
// bool bigFlag=false;//判断有没有出现唯一数
int i;
for(i=0;i<n-1;++i){
bool flag=false; //vi[i]是唯一
for(int j=i+1;j<n;j++){
if(vi[i]==vi[j]) {
vi[j]=0;
flag=true;
}
}
if(flag) vi[i]=0; //不是唯一
else{//是唯一
printf("%d\n",vi[i]);
// bigFlag=true;
break;
}
}//for
if(i==n-1) printf("None\n"); //整个数组没有唯一的
vi.clear();
}
return 0;
}