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;
}

ACM比赛(11462 Age Sort)的更多相关文章

  1. UVA 11462 Age Sort(计数排序法 优化输入输出)

    Age Sort You are given the ages (in years) of all people of a country with at least 1 year of age. Y ...

  2. UVa 11462 Age Sort

    解题报告:给若干个居民的年龄排序,年龄的范围在1到100之间,输入的总人数在0到200W.这题要注意的输入的文件约有25MB,而内存限制为2MB,所以如果人数是像200W这样多的话,甚至都不能把它们都 ...

  3. 11462 Age Sort(计数排序)

    内存不够用,用计数排序可以解决问题. #include<iostream> #include<cstdio> #include<cstdlib> #include& ...

  4. COGS 1406. 邻居年龄排序[Age Sort,UVa 11462](水题日常)

    ★   输入文件:AgeSort.in   输出文件:AgeSort.out   简单对比时间限制:1 s   内存限制:2 MB [题目描述] Mr.Zero(CH)喜闻乐见地得到了一台内存大大增强 ...

  5. 【输入输出挂】【Uva11462】Age Sort

    例题17  年龄排序(Age Sort, UVa 11462)照从小到大的顺序输出. [输入格式] 输入包含多组测试数据.每组数据的第一行为整数n(0<n≤2 000 000),即居民总数:下一 ...

  6. “玲珑杯”ACM比赛 Round #12题解&源码

    我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,日后补上剩余题的题解&源码吧!                                     A ...

  7. “玲珑杯”ACM比赛 Round #19题解&源码【A,规律,B,二分,C,牛顿迭代法,D,平衡树,E,概率dp】

    A -- simple math problem Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 SAMPLE INPUT ...

  8. ACM比赛经验

    这篇博客是转别人的,觉得很好,希望能在以后的现场赛中用上:ACM比赛经验 推荐此篇文章打印,与模板放在一起. 1. 比赛中评测会有些慢,偶尔还会碰到隔10分钟以上才返回结果的情况,这段时间不能等结果, ...

  9. Uva-------(11462) Age Sort(计数排序)

    B Age Sort Input: Standard Input Output: Standard Output   You are given the ages (in years) of all ...

随机推荐

  1. Objective-c 类接口 (@interface) (类定义)

    在Objective-c中如何定义一个类呢?我们可以使用下面的格式进行表示: @interface 类名:父类名{ 变量定义; } 方法定义: @end; 下面给出一个实例: @interface P ...

  2. Android API 中文(77)——AdapterView.OnItemSelectedListener

    前言 本章内容是android.widget.AdapterView.OnItemSelectedListener,版本为Android 2.3 r1,翻译来自"cnmahj",欢 ...

  3. Java自定义简单标签

     Java自定义简单标签可以方便的在页面输出信息,并且对于权限的控制,和对于Jsp标签和servlet代码的分离有着很好的作用. 下面将以权限的控制为例自定义一个标签: 一.标签类型 <wxt: ...

  4. Java基础--finalize()方法

    原理: 一旦垃圾回收器准备好释放对象占用的存储空间,将首先调用其finalize()方法,并在下一次垃圾回收动作发生时,才会真正回收对象占用的内存. 用途: 1)释放通过某种创建对象方式以外的方式为对 ...

  5. 第10季asp.net基础

    什么是ASP.Net: ASP.Net是一种动态网页技术,在服务器端运行.Net代码,动态生成HTML.可以使用javascript.Dom在浏览器端完成很多工作,但是有很多工作无法在浏览器端完成,比 ...

  6. 浅谈JDBC(一)

    一.JDBC技术引言 1.什么是JDBC技术 提供了一套接口规范,利用java代码进行数据库操作. 2.JDBC技术的核心思想 对于程序员来说,代码访问数据库分为三个步骤:1.通过数据库的账号密码.2 ...

  7. dede修改移动文档的js

    dede后台弹框修改: 想做个类似文章列表的移动功能,弹框,然后修改成功到表 先在list.js里复制一份moveArc的方法,到archives_do.php里复制一份moveArchives的方法 ...

  8. 数据切分——MySql表分区概述

    定义:         表的分区指根据可以设置为任意大小的规则,跨文件系统分配单个表的多个部分.实际上,表的不同部分在不同的位置被存储为单独的表.用户所选择的.实现数据分割的规则被称为分区函数,这在M ...

  9. IT第六天 - eclipse快捷操作、万年历项目的编写、菱形的打印输出、代码简化

    IT第六天 上午 小项目 1.程序提前结束的退出标志 2.登录用户的模拟,给出适当的提示信息 3.根据要求,寻找规律,然后编写程序 Eclipse的使用 1.快捷键的使用 下午 中小项目 1.九九乘法 ...

  10. [Android学习笔记5]四大应用组件之一:Service 下

    绑定方式的Service使用 在实现绑定服务时,最重要的是定义onBind()回调方法返回的接口,有三种方式: 1. 继承Binder类 2. 使用Messenger 3. 使用AIDL 这里对1,2 ...