CCF_201503-2_数字排序

自己写个排序的cmp。

 

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

struct  point{
    int num,counts;
}a[1005];

bool cmp(point x,point y)
{
    if(x.counts == y.counts)    return x.num < y.num;
    return x.counts > y.counts;
}

int main()
{
    int n,all = 0;
    cin >> n;
    for(int i = 0;i <= 1000;i++)
    {
        a[i].num = i;
        a[i].counts = 0;
    }
    int temp;
    while(n--)
    {
        cin >> temp;
        if(!a[temp].counts)    all++;
        a[temp].counts++;
    }
    sort(a,a+1001,cmp);
    for(int i = 0;i < all;i++) cout << a[i].num << ' ' << a[i].counts << endl;
    return 0;
}

 

posted @ 2016-09-06 03:16  zzzzzzzzhu  阅读(1004)  评论(1编辑  收藏  举报