题目描述
给出一些整数组,请编程每组整数,按各位数字的平方和的大小排序。
输入
每组整数第一行只有一个整数N,表示后继有N个整数需要排序,若表示整数组的个数为0,表示输入结束。
需要排序的整数个数<100
输出
输出排序结果
样例输入
9 12 567 91 33 657 812 2221 3 77 5 1 3 11 33 9 0
样例输出
12 3 2221 33 812 91 77 567 657 1 11 3 33 9
#include<stdio.h>
struct num{
int x,s;
};
struct num a[105],t;
int pf(int x)
{
int w=0;
while(x!=0)
{
w=w+(x%10)*(x%10);
x=x/10;
}
return w;
}
int main()
{
int n,i,j;
while(1)
{ scanf("%d",&n);
if(n==0) break;
for(i=0;i<n;i++)
{
scanf("%d",&a[i].x);