Grand pais Famous(poj 2092ソート)

3693 ワード

/*
http://poj.org/problem?id=2092
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#problem/D
Grand pais Famous
Time Limit:2000 MS
メモリLimit:30000 K
Total Submissions:7228
Acceepted:3653
Description
The whole family was excited by the news.Everyone knew grand pa had been extremely good bridge player for decades,but when it was henounced he woulesd be in the Ginness Book of Work Work Records the moriccess 
The International Bridge Asociation(IBA)has mantained,for several years,a weekly ranking of the best playrs in the world.Consindeng that ap apparce in a weekly ranking constites a point the playeminer 
Having many friends.who were also comppeting against him,grand pais extremilly curious to know which playr(s)took the second place.Since the IBAランキン秒are now available the inter interheturned.Henforyou.finds out which playr(s)got the second placcording to the number of points.
Input
The input contains several test cases.Players are e e dentifed by integers from 1 to 10000.The first line of a test case contatataininintersN and M indicatitititititiphively the number of rainininininininininininininininininininininininininininininininininininininininininininininininininininininings the of of of of of the the the the the the the thenumbeber of rankininininininininininininininininininininininindescription of one weekly ranking.Each description is compsed by a sequence of M integers,separated by a blank space,identiying the plays who figred in that weekly ranking.You can asume that: 
in each test case there is exactly oneベストプレーヤand at least one secondベストプレーヤ、 
each weekly ranking consists of M distinct player dentifers.
The end of input is indicated by N=M=0.
Output
For each test case in the input your program must produce one line of output、containing the ideantification number of the player who is second best in number of apearances in the ranking.If there is a tifor secondprint the identification numbers of all second best plears in increasung order.Each identification number produced must be followed by blank space.
Sample Input
4 5
20 33 25 32 99
32 86 99 25 10
20 99 10 33
19 33 74 99
3 6
2 34 67,36,79
100 38 21 76 91
32 23 85,3188 1
0
Sample Output
32
1 2 21 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 6 6 6 6 6 6 6 6 9 9 9 9 9 9 9 100。
ソurce
South America 2004
Acceepted
244 KB
172 ms
C++
919 B
2013-07-28 20:40:07
解析:
データのセットを指定します。出現回数第二のデータはその値をインクリメントした順に出力されます。
考え方:データの出現回数を並べて出力する
*/
#include<stdio.h>
#include<string.h>
#include<stack>
#include<vector>
#include<math.h>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=10000+10;
struct people
{     int po;
	int id;
}p[maxn];
bool cmp(people p1,people p2)
{
	return p1.po>p2.po||(p1.po==p2.po&&p1.id<p2.id);
}
int main()
{
	int n,m;
	int i,j;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		if(n==0&&m==0)
		break;
		int a;
	    memset(p,0,sizeof(p));
		for(i=0;i<n;i++)
		  for(j=0;j<m;j++)
		  {
		  	scanf("%d",&a);
		  	p[a].po++;
		  	p[a].id=a;
		  }
		  sort(p,p+maxn,cmp);
		  j=0;
		  while(p[j].po==0)
		  {j++;}
		  int t=p[j+1].po,ans=0;
		  for(i=j+1;i<maxn;i++)
		  {
		  	if(p[i].po==t)
		  	ans++;
		  }
		  for(i=j+1;i<maxn;i++)
		  {
		  	if(p[i].po==t)
		  	{  ans--;
		  	   printf("%d",p[i].id);
		  		if(ans)
		  		printf(" ");
		  		else
		  		printf("
"); } if(ans==0) break; } } return 0; }