现在的位置: 首页 > 综合 > 正文

RQNOJ133

2018年05月04日 ⁄ 综合 ⁄ 共 510字 ⁄ 字号 评论关闭
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXN 200010
#define LOCAL
int cmp(const void* a_, const void *b_);
int a[MAXN];
int main()
{
    #ifdef LOCAL
    freopen("ccc.txt", "r", stdin);
    #endif // LOCAL
    int n, i, j, b, tot;
    while((scanf("%d", &n))!=EOF){
        for(i=0; i<n; i++)
            scanf("%d", &a[i]);
        qsort(a,n,sizeof(int),cmp);
        for(i=0; i<n; i++){
            b=a[i];
            tot=1;
            for(j=i+1; j<n; j++){
                if(b==a[j])
                    tot++;
                else
                    break;
            }
            i=j-1;
            printf("%d %d\n", b, tot);
        }
    }
    return 0;
}

int cmp(const void* a_, const void *b_)
{
    int *a = (int*)a_;
    int *b = (int*)b_;
    if(*a <= *b)
        return -1;
    else
        return 1;
}

快排

【上篇】
【下篇】

抱歉!评论已关闭.