//数的统计 #include<stdio.h> #include<stdlib.h> int comp(const void *a,const void *b){ return *(int*)a - *(int*)b; } int main(){ int i,N,num=0; scanf("%d",&N); int a[2][N]; for(i=0;i<N;i++) scanf("%d",&a[0][i]); qsort(a[0],N,sizeof(int),comp); num = a[0][0]; a[1][0] = 1; for(i=1;i<N;i++){ if(a[0][i] == a[0][i-1]) a[1][i] = a[1][i-1] + 1; else{ printf("%d %d\n",a[0][i-1],a[1][i-1]); a[1][i] = 1; } } printf("%d %d",a[0][N-1],a[1][N-1]); return 0; }
原文地址:https://www.cnblogs.com/Hqx-curiosity/p/12245207.html
时间: 2024-11-07 11:38:54