码迷,mamicode.com
首页 > 其他好文 > 详细

Poj_2092 Grandpa is Famous

时间:2014-10-06 07:38:49      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   数据   

题目链接: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

标签:style   blog   http   color   io   os   ar   for   数据   

原文地址:http://www.cnblogs.com/tallisHe/p/4007895.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!