首页 > 代码库 > Poj_2092 Grandpa is Famous
Poj_2092 Grandpa is Famous
题目链接:http://poj.org/problem?id=2092
思路:
先统计数据,在根据Count降序排序,Count相等时按照Num升序排序;再输出Count第二大的所有Num;
代码:
#include <iostream>#include <string.h>#include <algorithm>using namespace std;#define MAX_N ( 10000 + 20 )struct Player{ int Num; int Count;};bool Cmp( Player a, Player b );int main(){ int n, m; Player P[MAX_N]; while( scanf("%d %d", &n, &m) ) { int Tmp, i, j; memset( P, 0, sizeof(P) ); if ( m == 0 && n == 0 ) break; for ( i = 0; i < n; ++i ) for( j = 0; j < m; ++j ) { scanf( "%d", &Tmp ); P[Tmp].Num = Tmp; P[Tmp].Count++; } sort( P, P + 10010, Cmp ); i = 1; while( P[i].Count == P[i+1].Count ) { printf("%d ", P[i].Num ); i++; } printf( "%d\n", P[i].Num ); } return 0;}bool Cmp( Player a, Player b ){ if ( a.Count == b.Count ) return a.Num < b.Num; else return a.Count > b.Count;}
Poj_2092 Grandpa is Famous
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。