水题 ZOJ 3869 Ace of Aces

 

题目传送门

 1 /*  2  水题:找出出现次数最多的数字,若多个输出Nobody  3 */  4 #include <cstdio>  5 #include <algorithm>  6 #include <cmath>  7 #include <iostream>  8 #include <cstring>  9 #include <string> 10 #include <map> 11 #include <set> 12 using namespace std; 13 14 const int MAXN = 1e3 + 10; 15 const int INF = 0x3f3f3f3f; 16 struct Hash 17 { 18 int num, cnt; 19 }hash[MAXN]; 20 21 bool cmp(Hash x, Hash y) 22 { 23 return x.cnt < y.cnt; 24 } 25 26 int main(void) //ZOJ 3869 Ace of Aces 27 { 28 //freopen ("A.in", "r", stdin); 29 30 int t, n; 31 scanf ("%d", &t); 32 while (t--) 33  { 34 memset (hash, 0, sizeof (hash)); 35 scanf ("%d", &n); 36 int x; 37 for (int i=1; i<=n; ++i) 38  { 39 scanf ("%d", &x); 40 hash[x].num = x; hash[x].cnt++; 41  } 42 43 sort (hash+1, hash+1+1000, cmp); 44 45 if (hash[1000].cnt == hash[999].cnt) puts ("Nobody"); 46 else printf ("%d\n", hash[1000].num); 47  } 48 }

 

你可能感兴趣的:(ZOJ)