n个数的排序 (sdut oj)

来源:互联网 发布:安全的理财软件 编辑:程序博客网 时间:2024/06/04 17:44


n个数的排序

Time Limit: 1000MS Memory Limit: 65536KB



Problem Description

 

LeiQ当上了体育委员,现在老师让他去给班级里的人排队,LeiQ刚学了排序,所以他想以这种方式给班级里的人排队(从矮到高),他想知道排序完成后的结果。


Input

 多组输入,每组的第一行是一个正数n(1<=n<=100),第二行是n个数,表示每一个人的高度。

 


Output

输出排序完成后的结果。


Example Input

3176 175 174


Example Output

174 175 176

Hint

 

Author








参考代码


#include<stdio.h>void sort(int *p,int n){    int i,j,temp;    for(i = 0; i < n - 1; i++)    {        for(j = i + 1; j < n; j++)        {            if(*(p+i) > *(p+j))            {                temp = *(p+i);                *(p+i) = *(p+j);                *(p+j) = temp;            }        }    }}int main(){    int n,i,a[100];    while(~scanf("%d",&n))    {        for(i = 0; i < n; i++)            scanf("%d",a+i);        sort(a,n);        for(i = 0; i < n; i++)        {            if(i == n - 1)                printf("%d\n",a[i]);            else                printf("%d ",a[i]);        }    }    return 0;}


0 0