码迷,mamicode.com
首页 > 其他好文 > 详细

A - Ace of Aces——ZOJ

时间:2016-05-12 15:57:30      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

A - Ace of Aces
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

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



利用数组储存,找到第一个第二大的数,然后比较!


#include<stdio.h>
#include<string.h>
#define MAX 2000
typedef struct node{
	int v;
	int c;
}NODE;
int main()
{
	int n,m,v[MAX],t,i,j,max,maxx,k,flag;
	NODE que[1005];
	scanf("%d",&n);
	for(k=1;k<=n;k++)
	{
		flag=0;
		memset(v,0,sizeof(v));
		scanf("%d",&m);
		for(i=1;i<=m;i++)
		{
			scanf("%d",&t);
			v[t]++;		
		}
		int len=0;
		for(i=1;i<MAX;i++)
		{
			if(v[i])
			{
				que[len].c=i;
				que[len].v=v[i];
				len++;
			}
		}
		max=0;
		for(i=0;i<len;i++)
		{
			if(max<que[i].v)
			{
				max=que[i].v;
				maxx=que[i].c;
				t=i;
			}
		}
		
		int temp=max;
		int tempx=maxx;
		que[t].v=-1;
		
		max=0;
		for(i=0;i<len;i++)
		{
			if(max<que[i].v)
			{
				max=que[i].v;
				maxx=que[i].c;
			}
		}
		
		if(max==temp)
			printf("Nobody\n");
		else
			printf("%d\n",tempx);
	}
	return 0;
}


A - Ace of Aces——ZOJ

标签:

原文地址:http://blog.csdn.net/chudongfang2015/article/details/51364064

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!