2015 HUAS Provincial Select Contest #1 B

题目:

Age Sort You are given the ages (in years) of all people of a country with at least 1 year of age. You know that no individual in that country lives for 100 or more years. Now, you are given a very simple task of sorting all the ages in ascending order.

Input

There are multiple test cases in the input file. Each case starts with an integer n (0 < n ≤ 2000000), the total number of people. In the next line, there are n integers indicating the ages. Input is terminated with a case where n = 0. This case should not be processed.

Output

For each case, print a line with n space separated integers. These integers are the ages of that country sorted in ascending order.

Warning: Input Data is pretty big (∼ 25 MB) so use faster IO.

题目大意:输入N个数 将它们按从小到大排序,遇到输入0程序结束

解题思路:讲输入的N个数存储到数组中,利用头文件algorithm中的sort()函数排列,再输出;

代码:

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7     int* a;
 8     int n;
 9     while(cin>>n)
10     {
11         if(n>0&&n<=2000000)
12         {
13             a=new int[n];
14             for(int i=0;i<n;i++)
15                 scanf("%d",&a[i]);
16             sort(a,a+n);
17             for(int j=0;j<n;j++)
18             {
19                 if(j!=(n-1))
20                 printf("%d ",a[j]);
21                 else  printf("%d",a[j]);
22             }
23             printf("\n");
24         }
25         else break;
26     }
27     return 0;
28 }

 

posted on 2015-07-16 19:33  最爱剪刀手  阅读(136)  评论(0编辑  收藏  举报