Ace of Aces Time limit: 2 Seconds Memory Limit: 65536 KB
There is a mysterious organization called Time-space administrative Bureau (TSAB) in the deep universe that we Hu Mans has not discovered yet. This year, the TSAB decided to elect a outstanding member from its elite troops. The elected guy would 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 would be elected as the "Ace of Aces". If there is, or more candidates has the same number of nominations, no one would win.
Tsab determine who'll be the "Ace of Aces".
Input
There is multiple test cases. The first line of input contains an integer indicating the number of the T 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, the output the ID of the candidate who would be honored with "Ace of Aces". If no one win the election, output "Nobody" (without quotes) instead.
Sample Input
352 2 2 1 151 1 2 2 31998
Sample Output
2nobody998
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace Std;
#define N 1010
struct node
{
int A, B;
}p[n];
BOOL CMP (Node A, Node B)
{
return A.A < B.A;
}
int main ()
{
int I, t, N, num;
scanf ("%d", &t);
while (t--)
{
scanf ("%d", &n);
for (i = 0; i < N; i++)
P[I].A = 0;
for (i = 1; I <= n; i++)
{
scanf ("%d", &num);
p[num].a++;
}
if (n = = 1)
printf ("%d", num);
Else
{
for (i = 1; i < 1010; i++)
p[i].b = i;
Sort (P, p+1010, CMP);
if (p[1009].a = = p[1008].a)
printf ("Nobody");
Else
printf ("%d", p[1009].b);
}
printf ("\ n");
}
return 0;
}
I don't know how long it's been written. What do you do when your head is not clear?
Be sure to think about things when you think about them.
Ace of Aces