一道C语言题!!帮忙!

来源:百度知道 编辑:UC知道 时间:2024/06/04 07:59:28
比如 输入一个数(自己输 随机的) scanf("%d",&n);
如:3
9638 8210 331
n=3
然后输3个数
!!!声明 数不是自己定的 然后把他们按每个位的数从小到大组成新数
如3689 218 133

#include <stdio.h>

void main()
{
int n,i,j,tot;
int a[10];
char s[100];
scanf("%d",&n);
for (i=1;i<=n;i++)
{
for (j = 0; j <= 9; j++) a[j]=0;
scanf("%s",&s);
j=0;
while (s[j])
{
a[s[j]-'0']++;
j++;
}
tot=0;
for (j=1;j<=9;j++)
{
tot = tot + a[j];
while (a[j]>0)
{
printf("%d",j);
a[j]--;
}
}
if (tot==0) printf("0");
printf("\n");
}
}