CSP考试 2015年03月第2题 数字排序 C语言实现

来源:互联网 发布:win10安装ubuntu分区 编辑:程序博客网 时间:2024/05/16 11:27


#include <stdio.h>int main(){int NUM;scanf("%d",&NUM);int a[NUM];int b[1001];    int i,j;    for(i=0;i<NUM;i++)    {    scanf("%d",&a[i]);}for(i=0;i<1001;i++){b[i]=0;}for(i=0;i<NUM;i++)    {    b[a[i]]++;    }/*    for(i=0;i<1001;i++){if(b[i]!=0)printf("b[%d]=%d\n",i,b[i]);}*/        while(1)    {    int max=0;    int temp=-1;    for(i=0;i<1001;i++){if(b[i]>max){max=b[i];temp=i;}}b[temp]=0;if(max==0){break;}printf("%d %d\n",temp,max);}return 0;}




0 0
原创粉丝点击