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

做把自以为是的好人~ ~ ~ ~ ^_^ 448K 32MS.

Posted by WHQ557 at 2012-09-07 15:43:36 on Problem 2092
#include<stdio.h>
#include<string.h>
#include<algorithm>

using namespace std;

typedef struct{
    short id;
    short num;
}node;

node vis[10002];
short nvis[10002];

bool cmp(node a,node b){
    if(a.num!=b.num) return a.num>b.num;
    return a.id<b.id;
}

void scan(short &p){
    p=0;
    char c;
    while(c=getchar(),'0'<=c&&c<='9'){
        p=p*10+c-'0';
    }
    if(!p) scan(p);
}

int main(){
    short n,m;
    while(scanf("%hd%hd\n",&n,&m),n&&m){
        memset(vis,0,40008);
        memset(nvis,0,20004);
        short size=1,i,j,x;
        for(i=0;i<n;++i){
            for(j=0;j<m;++j){
                scan(x);
                if(nvis[x]){
                    ++vis[nvis[x]].num;
                }
                else{
                    nvis[x]=size;
                    vis[size].id=x;
                    vis[size++].num=1;
                }
            }
        }
        sort(vis+1,vis+size,cmp);
        i=2;
        while(vis[i].num==vis[i-1].num) ++i;
        printf("%hd ",vis[i++].id);
        while(vis[i].num==vis[i-1].num){
            printf("%hd ",vis[i++].id);
        }
        putchar('\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