Problem1829--第1题 1.数的排序

1829: 第1题 1.数的排序

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MB

Description

输入n个不超过30000的整数(n≤10)。然后求出每个数的数字和,再按每个数的数字和由小到大排列输出。

Input

第一行为整数n 
第二行为n个整数

Output

由小到大排列的每个数的数字和(每个数之间保留一个空格)

Sample Input Copy

4
33 104 87 16

Sample Output Copy

5 6 7 15

HINT

#include<iostream>

#include<cstdio>

using namespace std;

int a[15],n,x;

int main()

{

    freopen("sort.in","r",stdin);

    freopen("sort.out","w",stdout);

    cin>>n;

    for(int i=1;i<=n;i++)

     {

                       ;

        int y=0;

        while(x>0)

        {

                           ;

            x=x/10;

        }

                         ;

     }

     for(int i=1;i<n;i++)

      for(int j=             ;j<=n;j++)

         if( a[i]>a[j] )  swap(a[i],a[j]);

    for(int i=1;i<=n;i++)

     cout<<a[i]<<" ";

  return 0;

}


参考答案:(1)cin>>x(2)y+=x%10(3)a[i]=y  (4)i+1  (5)a[i]>a[j]



Source/Category