Title: The second person in the ranking.
Analysis: Count sorting + statistics.
Note: rhubarb says there is a problem with the topic. How can he put it in the DP category. )
#include <iostream>#include <cstdlib>#include <cstring>#include <stdio.h>usingnamespace std;int V[ 10005 ];int C[ 10005 ];int cmp( constvoid* a, constvoid* b ){ return *(int *)b - *(int *)a;}int main(){ int N,M,I; while ( cin >> N >> M && (N||M) ) { memset( V, 0, sizeof( V ) ); memset( C, 0, sizeof( C ) ); for ( int i = 1 ; i <= N ; ++ i ) { for ( int j = 1 ; j <= M ; ++ j ) { scanf("%d",&I); ++ C[ I ]; ++ V[ I ]; } } qsort( C, 10001, sizeof( int ), cmp ); int v = 0; for ( int i = 1 ; ; ++ i ) { if ( C[ i ] != C[ i-1 ] ) { v = C[ i ]; break; } } if ( !v ) continue; for ( int i = 1 ; i <= 10000 ; ++ i ) { if ( V[ i ] == v ) { printf("%d ",i); } } printf("\n"); } return 0;}
Zoj 2250-grandpa is famous