文章
38
粉丝
74
获赞
130
访问
40.0k
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
    int num;
    int count;
}node;
int n;
struct node p[10009];
int cmp(const void*a,const void*b)
{
    struct node a1=*(struct node*)a;
    struct node b1=*(struct node*)b;
    if(a1.count!=b1.count)return b1.count-a1.count;
    else return a1.num-b1.num;
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<10009;i++){
        p[i].num=i;
        p[i].count=0;
    }
    for(int i=0;i<n;i++){
        int a;
        scanf("%d",&a);
        p[a].count++;
    }
    qsort(p,10009,sizeof(struct node),cmp);
    printf("%d",p[0].num);
    return 0;
}
先对次数排序,在对下标排序
登录后发布评论
暂无评论,来抢沙发