題意:給出一個個數爲n的序列,求出其中的衆數,若有多個衆數,則輸出Nobody
鏈接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5517
思路:排序後統計衆數
注意點:無
以下爲AC代碼:
Run ID | Submit Time | Judge Status | Problem ID | Language | Run Time(ms) | Run Memory(KB) | User Name |
3945629 | 2015-04-26 22:50:14 | Accepted | 3869 | C++0x | 0 | 352 | luminus |
/*
***********************************************
*# @Author : Luminous11 ([email protected])
*# @Date : 2015-04-26 22:41:59
*# @Link : http://blog.csdn.net/luminous11
***********************************************
*/
#include <bits/stdc++.h>
#define clr(a, v) memset( a , v , sizeof(a) )
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1.0);
struct node
{
int cnt, k;
};
node num[10005];
bool operator< ( const node & a, const node &b )
{
return a.cnt > b.cnt;
}
int main()
{
ios::sync_with_stdio ( false );
int T;
scanf ( "%d", &T );
while ( T -- ){
int n;
scanf ( "%d", &n );
memset ( num, 0, sizeof ( num ) );
int tmp;
for ( int i = 0; i < n; i ++ ){
scanf ( "%d", &tmp );
num[tmp].cnt ++;
num[tmp].k = tmp;
}
sort ( num, num + 1005 );
if ( num[0].cnt > num[1].cnt ){
printf ( "%d\n", num[0].k );
}
else{
printf ( "Nobody\n" );
}
}
return 0;
}