算法训练——数的统计
//数的统计 #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; }
相关推荐
湾区人工智能 2020-11-20
Pokemogo 2020-11-16
baijingjing 2020-11-16
baijingjing 2020-11-15
Site 2020-11-07
lwnylslwnyls 2020-11-06
justaipanda 2020-11-05
MachineIntellect 2020-11-02
xueyuediana 2020-10-30
GeraldJones 2020-10-30
Tips 2020-10-29
baijingjing 2020-10-28
baijingjing 2020-10-27
硕鼠 2020-10-26
playoffs 2020-10-26
scuyxi 2020-10-25
playoffs 2020-10-25
yise001 2020-10-23