Poj_2092 grandpa is famous

Source: Internet
Author: User

Question link: http://poj.org/problem? Id = 2092

 

Ideas:

First, statistical data is sorted by count in descending order. If count is equal, data is sorted by num in ascending order. Then, all the num with the second largest count is output;

Code:
#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.