<pre name="code" class="cpp">#include<stdio.h> int main() { int flag[1000]={0}; int tmp,i; //for(i=0;i<1000;i++)flag[i]=0; printf("How many numbers?\n"); scanf("%d",&tmp); while(tmp--) { scanf("%d",&i); flag[i]++; } tmp=1000; while(tmp--) { if(flag[tmp])while(flag[tmp]--)printf("%d ",tmp); } }
v2.0:
#include<stdio.h>
int main()
{
int flag[1000]={0};
int tmp,i;
//for(i=0;i<1000;i++)flag[i]=0;
printf("How many numbers?\n");
scanf("%d",&tmp);
while(tmp--)
{
scanf("%d",&i);
flag[i]++;
}
tmp=1000;
while(tmp--)
{
if(flag[tmp])while(flag[tmp]--)printf("%d ",tmp);
}
}
时间: 2024-11-08 20:40:52