ZOJ3869(桶排序&结构体排序)

Description

There is a mysterious organization called Time-Space Administrative Bureau (TSAB) in the deep universe that we humans have not discovered yet. This year, the TSAB decided to elect an outstanding member from its elite troops. The elected guy will be honored with the title of "Ace of Aces".

After voting, the TSAB received N valid tickets. On each ticket, there is a number Ai denoting the ID of a candidate. The candidate with the most tickets nominated will be elected as the "Ace of Aces". If there are two or more candidates have the same number of nominations, no one will win.

Please write program to help TSAB determine who will be the "Ace of Aces".


Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first line contains an integer N (1 <= N <= 1000). The next line contains N integers Ai (1 <= Ai <= 1000).

Output

For each test case, output the ID of the candidate who will be honored with "Ace of Aces". If no one win the election, output "Nobody" (without quotes) instead.

Sample Input
3
5
2 2 2 1 1
5
1 1 2 2 3
1
998
Sample Output
2
Nobody
998



题意大致为:给出每个人的票数,求票数最多的人是谁,若有两个人票数同样(并且两个人的票数都是最多的)则Nobody。

这一看就是一道很水的题,就是桶排啊,可开始我却理解错了题意(漏掉了上面那个括号里的重要信息),无脑的我写个无数次,WA了无数发也没想到才看下题意,发现比赛结束只有我一个人没有过T_T。理解对题意后却不会写了,听完我宇哥讲解之后 哇!!!orz orz
在我看来我宇哥的代码很短 很短~~~~^_^~~~~

求大佬们多多指点
/*
The author:××××
*/
#include<stdio.h>
#include<string.h>
int a[1005];
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		int max = 0;
        int min = 0;
        memset(a,0,sizeof(a)); 
        int n;
        scanf("%d",&n);
 		int c;
		for(int i = 0;i<n;i++){
			int b;
			scanf("%d",&b);
			a[b]++;
			if(a[b]>=max){//核心部分代码
				min=max;
				max=a[b];
				c=b;
			}
		}
 		if (min==max) //
			printf("Nobody\n"); 
 		else 
			printf("%d\n",c);
	}
return 0;
}

 明天再附上结构体的写法

原文地址:https://www.cnblogs.com/gjy963478650/p/7241703.html