码迷,mamicode.com
首页 > 其他好文 > 详细

oj-ccf-csp-201312-1-出现次数最多的数

时间:2017-06-01 22:06:04      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:clu   names   max   log   const   node   while   color   scanf   

 

 

#include<cstdio>
#include<algorithm> 
using namespace std;
const int maxn=10005;
struct node{
    int index;
    int cnt;
    node(int _index=-1, int _cnt=0): index(_index),cnt(_cnt){}
}Node[maxn];
bool cmp(node a,node b){
    if(a.cnt!=b.cnt) return a.cnt>b.cnt;
    else return a.index<b.index;
}
int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        int index;
        for(int i =1;i<n+1;i++){
            if(i>=2) scanf("%c");
            scanf("%d",&index);
            Node[index].index=index;
            Node[index].cnt++;
        }
    
        sort(Node+1,Node+10001,cmp);
        printf("%d\n",Node[1].index);

    }
    return 0;
}

 

oj-ccf-csp-201312-1-出现次数最多的数

标签:clu   names   max   log   const   node   while   color   scanf   

原文地址:http://www.cnblogs.com/kprac/p/6930936.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!