题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3860
水题,问给出的数组中唯一不一样的那个是多少。
1 #include <iostream> 2 #include <cstring> 3 #include <string> 4 #include <cstdio> 5 #include <vector> 6 #include <cmath> 7 #include <algorithm> 8 using namespace std; 9 int T, N; 10 int a[110]; 11 int main(){ 12 scanf("%d", &T); 13 while(T--){ 14 scanf("%d", &N); 15 int x1, x2; 16 int sum1 = 0, sum2 = 0; 17 for(int i = 1; i <= N; i++){ 18 scanf("%d", &a[i]); 19 } 20 x1 = a[1]; 21 sum1 = 1; 22 for(int i = 2; i <= N; i++){ 23 if(a[i] != x1){ 24 sum2++; 25 x2 = a[i]; 26 } 27 else sum1++; 28 29 } 30 if(sum1 == 1) cout<<x1<<endl; 31 else cout<<x2<<endl; 32 33 } 34 35 return 0; 36 }
时间: 2024-10-06 15:05:08