Problem description a given n positive integers, sorted according to the sum of the numbers and from small to large. Input data has multiple groups, one row per group of data, and the first number of each row is a positive integer n, representing an integer number followed by n positive integers. When n is 0 o'clock, no processing is done and the input ends. N<=10output outputs the results of each set of sorts. Example Input
2 1 23 121 10 1110
Example Output
1 210 111 121
Hint
#include <stdio.h> #include <stdlib.h>int f (int n)//write a number that calculates the sum of the figures. { int sum=0; while (n!=0) { sum+=n%10; N=N/10; } return sum;} int main () { int n; int *num, I, J, temp; while (scanf ("%d", &n)!=eof) { if (n==0) return 0; Num=malloc (sizeof (int) *n); for (i=0; i<n; i++) scanf ("%d", &num[i]); For (I=1, i<n; i++) for (j=0; j<n-i; j + +) { if (f (num[j]) >f (num[j+1])) { temp=num[j +1]; NUM[J+1]=NUM[J]; num[j]=temp; } } for (i=0; i<n; i++) { if (i==0) printf ("%d", Num[i]); else printf ("%d", Num[i]); } printf ("\ n");} }
AC Diary--the sum of the numbers of 23--