yusijia’s blog ZOJ 3869

Contents

题目大意:

  输出出现次数最多的数如果有两个或两个以上数量相等的,就输出Nobody

  • 快排
  • 定义结构体记录下标和出现次数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39


#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;

struct Node{
int id;
int counts;
}node[1010];

bool (Node a, Node b)
{
return a.counts > b.counts;
}

int main()
{
int T, n, tmp;
scanf("%d", &T);
while(T--){
memset(node, 0, sizeof(node));
scanf("%d", &n);
for(int i = 0; i < n; i++){
scanf("%d", &tmp);
node[tmp].id = tmp;
node[tmp].counts++;
}
sort(node, node + 1010, cmp);

if(node[0].counts == node[1].counts)
printf("Nobodyn");
else
printf("%dn", node[0].id);
}
return 0;
}