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 le. Each case starts with an integer
n(0<=n<=200000)
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.
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函数。还有就是可能会有很多会把数组a开在主函数,非常建议大家不要这样,这样也会很耗时。

程序代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int a[2000000];
int main( )
{int i,n ,j,t,k;
while(scanf("%d",&n)==1&&n)
{for(i=0;i<n;i++)
cin>>a[i];
sort(a,a+i);
for(i=0;i<n-1;i++)
printf("%d ",a[i]);
printf("%d\n",a[n-1]); }
return 0;
}

最新文章

  1. 注解:【基于主键的】Hibernate1-&gt;1关联
  2. BZOJ1801:[Ahoi2009]chess 中国象棋
  3. Swift开发小技巧--自定义转场动画
  4. rhel7防止开机破密码
  5. Android酷炫实用的开源框架——UI框架(转)
  6. poj1159 dp最长公共子串
  7. 用php自带的filter函数验证、过滤数据 -转载
  8. codevs 3052 多米诺 二分图匹配
  9. JS高级程序设计学习笔记之基本包装类型
  10. ASP.NET JQuery Ajax 详解
  11. 一款简单的客户端安卓手机qq源码
  12. Hands-On Machine Learning with Scikit-Learn and TensorFlow---读书笔记
  13. Django学习-12-模板继承
  14. 利用 pyspider 框架抓取猫途鹰酒店信息
  15. Can`tconnect to MySQL server on &#39;localhost&#39;(10061)问题解决
  16. javaweb 项目启动问题:Application Server was not connected before run configuration stop, reason: javax.manage
  17. SQLServer截取字符串常用函数
  18. Python自学笔记-装饰器1(廖雪峰的网站)
  19. oracle 查看表空间使用情况
  20. SqlServer导入Excel数据

热门文章

  1. projecteuler----&amp;gt;problem=8----Largest product in a series
  2. BCS--设置BDC元数据存储权限--访问被业务数据拒绝
  3. UILabel显示html文本
  4. mfc主窗口添加背景图片后,如何实现在背景图片上输出文字
  5. 在Visual Studio中使用FFTW库
  6. leetcode208 happynumber
  7. 阿里云部署 Flask + WSGI + Nginx 详解
  8. MySQL PrepareStatement基本的两种模式&amp;客户端空间占用的源码分析
  9. 从零开始学C++之IO流类库(四):输出流格式化(以操纵子方式格式化 以ios类成员函数方式格式化)
  10. ios中利用NSDateComponents、NSDate、NSCalendar判断当前时间是否在一天的某个时间段内。