1923: 排序
时间限制: 1 Sec 内存限制: 32 MB
献花: 171 解决: 89
[献花][花圈][TK题库]
题目描述
对输入的n个数进行排序并输出。
输入
输入的第一行包括一个整数n(1<=n<=100)。 接下来的一行包括n个整数。
输出
可能有多组测试数据,对于每组数据,将排序后的n个整数输出,每个数后面都有一个空格。
每组测试数据的结果占一行。
样例输入
5
5 4 3 1 2
样例输出
1 2 3 4 5
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
const int MaxN = 100;
int main()
{
#ifdef _DEBUG
ifstream cin("data.txt");
#endif // _DEBUG
int n;
int Num[MaxN];
while (cin >> n)
{
for (int i = 0; i < n; ++i)
cin >> Num[i];
sort(Num, Num + n);
for (int i = 0; i < n; ++i)
{
cout << Num[i];
if (i != n - 1)
cout << " ";
}
cout << endl;
}
#ifdef _DEBUG
cin.close();
system("pause");
#endif // _DEBUG
return 0;
}
/**************************************************************
Problem: 1923
User: Sharwen
Language: C++
Result: 升仙
Time:5 ms
Memory:1708 kb
****************************************************************/