11547: 【原1547】tros
题目
题目描述
author: Zhijian Liu 原OJ链接:https://acm.sjtu.edu.cn/OnlineJudge-old/problem/1547
Description
排序
Input Format
第一行一个整数\(t\), 代表有\(t\)组数据需要排序.
接下来\(2t\)行, 每两行中第一行一个整数\(n\), 接下来一行\(n\)个整数, 代表待排序的数组.
Output Format
输出共\(t\)行, 每行输出从小到大排序之后的数.
Sample Input
2
5
1 3 2 4 5
8
1 9 2 6 0 8 1 7
Sample Output
1 2 3 4 5
0 1 1 2 6 7 8 9
Limits
对于\(50\%\)的数据, \(n\leq1000\).
对于\(100\%\)的数据, \(n\leq200000\).
对于\(100\%\)的数据, \(t\leq 5\).
不允许使用C语言或者C++语言自带的排序函数, 不允许使用基数排序, 否则都将被判为0分.
yyong119's solution
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX_N = 200010;
int k, n;
int a[MAX_N];
int main() {
ios::sync_with_stdio(false);
cin >> k;
while (k--) {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
sort(a + 1, a + 1 + n);
for (int i = 1; i < n; ++i) cout << a[i] << " ";
cout << a[n] << endl;
}
return 0;
}