Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

不用排序,map水过

Posted by 201211050121 at 2013-11-19 08:36:15 on Problem 2092
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;
map<int,int>mp;
map<int,int >::iterator it;
int main()
{
    //freopen("in.txt","r",stdin);
    int m,n;
    while(scanf("%d%d",&m,&n)!=EOF)
    {
        if(n==0&&m==0)  break;
        mp.clear();
        int num;
        for(int i=0;i<n*m;i++)
        {
            scanf("%d",&num);
            mp[num]++;
        }
        int arr[10001];
        int cnt=0;
        for(it=mp.begin();it!=mp.end();it++)
            arr[cnt++]=it->second;
        sort(arr,arr+cnt);
         for(it=mp.begin();it!=mp.end();it++)
         {
             if(it->second==arr[cnt-2])
                printf("%d ",it->first);
         }
         printf("\n");
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator