数组
** xdoj–数字排序**
#include<stdio.h>
int main()
{
int n, i;
scanf("%d\n",&n);
int a[1000];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int b[1000] = {0};
for(i=0;i<n;i++)
{
int temp = a[i];
for(int x=0;temp!=0;x++)
{
b[i] += temp%10;
temp /= 10;
}
}
for(i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(b[i]<b[j])
{
int tem = b[i], temp1 = a[i];
b[i] = b[j]; a[i] = a[j];
b[j] = tem;a[j] = temp1;
}
else if(b[i]==b[j])
{
if(a[i]>a[j])
{
int temp1 = a[i];
a[i] = a[j];
a[j] = temp1;
}
}
}
}
for (i=0;i<n;i++)
{
printf("%d %d\n",a[i],b[i]);
}
return 0;
}