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. vs linq to db template

    linq to db template 支持sqlite. mysql .db2. accress. oracle. Firebird等多种数据库以linq方式操作数据. NuGet NuGet 是 ...

  2. Ext.MessageBox.Show使用Progress

    在此之前,先添加引用:以下引用方式仅供参考:由于我的extjs文件夹放在script文件夹下 <link href="~/Scripts/extjs/resources/ext-the ...

  3. SASS安装的那些事

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  4. photoshop使用注意事项

    CMYK 与 RGB 任何网络图片都会以RGB模式显示图片: 数码图片以RGB模式被捕捉,因此应在RGB模式下编辑: 大部分工具和滤镜只能在RGB模式下使用: RGB模式和CMYK模式之间不能实现无损 ...

  5. 新技能get: 使用whois查询不明网址的信息

    1.站长之家-->Whois反查 http://whois.chinaz.com/ 进入whois.chinaz.com,输入要查询的网址,选择查询即可.

  6. qnx:从API开始理解QNX -- 消息传递

    从API开始理解QNX -- 消息传递    http://www.openqnx.com/chinese/viewtopic.php?f=5&t=2161 1. 频道与连接    Chann ...

  7. CSS技巧!像table一样布局div

    摘自:http://www.cnblogs.com/hnyei/archive/2011/09/19/2181442.html 许多网页设计师都喜欢,将两个或者多个容器等高的并排放置,并在里面展示每个 ...

  8. QT学习 之 QwtPlot(数学绘图)

    QT对于统计图像.函数图像等的绘制是没有相关组件的帮助的,只有利用手工绘制图片. QwtPlot是用来绘制二维图像的widget,继承自QFrame 和 QwtPlotDict.不过严格的说来,它只是 ...

  9. Qt5制作鼠标悬停显示Hint的ToolTip

    在日常生活中的使用的软件中,我们经常会遇到这样的情况. 我们在网页上,有些网页链接的文字(比如文章标题,知乎问题标题,百度的词条等)因为太长了,而显示不出来,但是鼠标悬停在上面的时候就可以显示出来.  ...

  10. Gartner 认可 Microsoft 为应用程序平台即服务的领导者

    对于 Windows Azure 而言,2013 年是了不起的一年.客户使用量每月都创新高:4 月份 Windows Azure 基础结构服务一经正式发布即受到前所未有的青睐,成为重要的里程碑.Gar ...