训练1-N

给出N个整数,对着N个整数进行排序

Input
第1行:整数的数量N(1 <= N <= 50000)
第2 - N + 1行:待排序的整数(-10^9 <= Ai <= 10^9)
Output
共n行,按照递增序输出排序好的数据。

Sample Input
5
5
4
3
2
1
Sample Output
1
2
3
4
5
#include<stdio.h>
#include<algorithm>                        //要用到sort函数,所以要定义头文件
using namespace std;                       
int main()
{
	long n,i,j;                        //题中范围都比较大,定义为long,只要超过32767就不能再用int型
	long temp,a[50000];
	scanf("%ld",&n);
	for(i=0;i<n;i++)
	scanf("%ld",&a[i]);
        sort(a,a+n);                      //sort函数排序,用法sort(数组名,数组名+长度)
	for(i=0;i<n;i++)
	printf("%ld\n",a[i]);
	return 0;
}

...

posted @ 2018-06-05 19:02  浮生惘语  阅读(86)  评论(0编辑  收藏  举报