游客 Signup | Login
中文 | En

2257 - b1006

用函数实现用选择法对10个整数按降序排列,输出排序结果。

Input

Output

Examples

Input

1 3 4 2 5 6 8 7 9 2

Output

9 8 7 6 5 4 3 2 2 1

Hint

注意判断整数的大小相同时的情况

Solution C

#include<stdio.h>
int main()
{
    int t,a[10],i,j;
    for(i=0;i<10;i++)
        scanf("%d",&a[i]);
    for(i=0;i<9;i++)
        for(j=0;j<9-i;j++)
    {
        if(a[j]<a[j+1])
        {
          t = a[j];
          a[j]=a[j+1];
          a[j+1]=t;
        }
    }
    for(i=0;i<9;i++)
        printf("%d ",a[i]);
    printf("%d\n",a[i]);
}

Solution C++

#include<iostream>
#include<cstdio>
#include<iostream>
#include<cmath>

using namespace std;

int main(){
    int a[15];
    for(int i=0;i<10;i++)
        cin>>a[i];
    for(int i=0;i<9;i++)
        for(int j=0;j<9-i;j++)
            if(a[j] < a[j+1]){
                int temp = a[j];
                a[j] = a[j+1];
                a[j+1] = temp;
            }
    cout<<a[0];
    for(int i=1;i<10;i++)
        cout<<' '<<a[i];
    cout<<endl;
    return 0;
}

Hint

注意判断整数的大小相同时的情况

Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题