11462 - Age Sort

题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=26739

题目大意:

     给出数组年龄数据,每组有n(0<n<=2000000)个数据,要求按从小到大的顺序进行排列,需要注意的是输入的数据有可能比较多,所以需要使用更快的IO

     案例:

 

           Sample Input
              5
              3 4 2 1 5
              5
              2 3 2 3 1
              0
              Sample Output
              1 2 3 4 5
              1 2 2 3 3

 

题目分析:

     多组数据,需注意的是数据大小不定,则可以在函数体外进行数组的定义后,再运用sort函数对数组进行排列,另外要注意数据的输出格式!

源代码:

 

 1 #include<cstdio>
 2 #include<algorithm>
 3 using namespace std;
 4 const int maxn=2000000;
 5 int a[maxn];//函数体外定义数组
 6 int n;
 7 int main()
 8 {
 9     
10     while(scanf("%d",&n)&&n)
11     {
12         for(int i=0;i<n;i++)
13            scanf("%d",&a[i]);//输入年龄
14         sort(a,a+n);//排序
15         printf("%d",a[0]);
16          for(int j=1;j<n;j++)//注意空格输出格式
17            printf(" %d",a[j]);
18         printf("\n");
19     }
20     return 0;
21 }

 

posted @ 2015-07-17 19:45  ~瞬间*  阅读(165)  评论(0编辑  收藏  举报