公司网站.可以自己做吗/seo服务包括哪些
题目描述:
对输入的n个数进行排序并输出。
输入:
输入的第一行包括一个整数n,(1<=n<=100)。接下来的一行包括n个整数。
输出:
可能有多组测试数据,对于每组数据,输出排序后的n个整数,每个数后面都有一个空格。每组测试数据的结果占一行。
样例输入:
4
1 4 3 2
样例输出:
1 2 3 4
c++内部有一个基于快速排序的函数sort,只需调用这个函数,便能轻易完成排序。
sort(first,last,comp):first和last为待排序序列的起始地址和结束地址;comp为排序方式,可以不填写,不填写时默认为升序方式。
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 100;
int arr[maxn];int main() {int n;while (scanf("%d", &n) != EOF) {for (int i = 0; i < n; i++) {scanf("%d", &arr[i]);}sort(arr, arr + n);for (int i = 0; i < n; i++) {printf("%d ", arr[i]);}printf("\n");}return 0;
}