题解 | #牛牛的排序#
牛牛的排序
http://www.nowcoder.com/practice/26a0c92e9266443887a3bf81aff8e188
#include <bits/stdc++.h>
using namespace std;
int main() {
// a存储数组长度
int a;
scanf("%d", &a);
// 设置整数类型的数组指针,使用数组长度a分配空间大小,不然编译不通过
int *b = (int*) malloc(a*sizeof(int));
// for循环加scanf逐个读取数字存入数组b
for (int i = 0; i < a; i++) scanf("%d", &b[i]);
// sort函数实现排序,注意传入参数的区间问题
sort(b, b + a);
// 然后for输出就完事了
for (int j = 0; j < a; j++) cout << b[j] << " ";
return 0;
}
