您的位置:首页 > 其它

水题 ZOJ 3869 Ace of Aces

2015-04-26 13:37 176 查看
题目传送门

水题,找出出现次数最多的数字,若多个输出Nobody

//#include <bits/stdc++.h>
//using namespace std;
#include <cstdio>   //stdio.h
#include <cstring>  //string.h
#include <algorithm>

const int N = 1e3 + 5;
struct Hash   {
int num, cnt;
bool operator < (const Hash &r) const {
return cnt < r.cnt;
}
}h
;

//bool cmp(const Hash &a, const Hash &b)    {   //更规范的写法
bool cmp(Hash a, Hash b)    {
return a.cnt < b.cnt;       //按照计数cnt从小到大排
}

int main(void)  {
int T;  scanf ("%d", &T);
while (T--) {
int n;  scanf ("%d", &n);
memset (h+1, 0, sizeof (h));
for (int x, i=1; i<=n; ++i) {
scanf ("%d", &x);
h[x].num = x;   h[x].cnt++;
}
//std::sort (h+1, h+1+1000, cmp);       //cmp比较函数写在结构体外面
std::sort (h+1, h+1+1000);              //结构体重载运算符 '<'
if (h[1000].cnt == h[999].cnt)  puts ("Nobody");
else    printf ("%d\n", h[1000].num);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: