0
点赞
收藏
分享

微信扫一扫

HUST-排序


题目链接

​​https://www.nowcoder.com/practice/508f66c6c93d4191ab25151066cb50ef?tpId=40&tqId=21542&tPage=1&rp=1&ru=/ta/kaoyan&qru=/ta/kaoyan/question-ranking​​

题目描述

    对输入的n个数进行排序并输出。

输入描述:

输入的第一行包括一个整数n(1<=n<=100)。
接下来的一行包括n个整数。

输出描述:

可能有多组测试数据,对于每组数据,将排序后的n个整数输出,每个数后面都有一个空格。
每组测试数据的结果占一行。

示例1

输入

复制

4
1 4 3 2

输出

复制

1 2 3 4

题解:

#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(int a, int b){
return a < b;
}
int main(){
int n;
while(cin >> n){
int buf[100];
for(int i = 0; i < n; i++){
cin >> buf[i];
}
sort(buf, buf + n, cmp);
for(int i = 0; i < n; i++){
cout << buf[i] << " ";
}
cout << endl;
}
}

 

举报

相关推荐

0 条评论