题目描述:
对输入的n个数进行排序并输出。
输入:
输入的第一行包括一个整数n(1<=n<=100)。
接下来的一行包括n个整数。
输出:
可能有多组测试数据,对于每组数据,将排序后的n个整数输出,每个数后面都有一个空格。
每组测试数据的结果占一行。
样例输入:
4
1 4 3 2
样例输出:
1 2 3 4
/*
*很简单很基础的一道题目,就不多说了,希望初学者能够学习到
*/
#include <cstdio>
#include <algorithm>
#include <cctype>
using namespace std;
//这个函数是从缓冲区接收int型的,并且会把下一个字符接收,如果接收到int返回true
inline bool getint(int &x){
x = 0;
int mute = 1;
char c;
while(!isdigit(c = getchar()) && c != '-')
if(c == -1)
return false;
c == '-' ? mute = -1 : x = c - '0';
while(isdigit(c = getchar()))
x = (x << 1) + (x << 3) + c - '0';
x *= mute;
return true;
}
//sort函数的比较器,这样比较是从小到大排序,据我观察,sort应该是不稳定的,stable_sort才是稳定的
//具体区别现在还说不上来,请详细研究
inline bool cmp(int a, int b){
return a < b;
}
int a[101];
int main(){
int n;
while(getint(n)){
for(int i = 0; i < n; i++)
getint(a[i]);
sort(a, a + n);
for(int i = 0; i < n; i++)
printf("%d ", a[i]);
puts("");
}
};