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. Dropping tests(01分数规划)

    Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8176   Accepted: 2862 De ...

  2. js 特效 手风琴效果

    $(document).ready(function(){ //定义展开的块 var lastBlock = $('#a1'); //展开的块的宽度 var maxWidth = 406; //折叠的 ...

  3. 写一个背景渐变的TextView输入框

    1:在res文件夹下新建一个drawble文件夹,并新建一个背景文件如writebg.xml <?xml version="1.0" encoding="utf-8 ...

  4. CodeForces 443B Kolya and Tandem Repeat

    题目:Click here 题意:给定一个字符串(只包含小写字母,并且最长200)和一个n(表示可以在给定字符串后面任意加n(<=200)个字符).问最长的一条子串长度,子串满足前半等于后半. ...

  5. 总线接口与计算机通信(四)USB外部总线(初级认识)

    USB简介   USB是英文Universal Serial BUS(通用串行总线)的缩写,是一个外部总线标准,用于规范电脑与外部设备的连接和通讯,是应用在PC领域的接口技术.USB接口支持设备的即插 ...

  6. TCP粘包和半包的处理方法

    先把处理的方法的代码放这里: 解析数据帧的代码: bool CSocket::findData(byte* buff, int& len) { for (int i = 0; i <= ...

  7. [javascript]MooTools Selectors(MooTools 选择器) ELEMENT DOM选择

    //ELEMENT DOM选择//on are tag names. //All the divs on the page: $$('div'); //All the divs and paragra ...

  8. 更改firefox默认搜索引擎

    使用Organizie Search Engines 这个插件  这个插件似乎不能添加搜索引擎 但是可以修改搜索引擎 好吧 由于有时候firefox会自动更新搜索引擎  所以不要对Google搜索引擎 ...

  9. 数据切分——Mysql分区表的建立及性能分析

    Mysql的安装方法可以参考: http://blog.csdn.net/jhq0113/article/details/43812895 Mysql分区表的介绍可以参考: http://blog.c ...

  10. C的memset,memcpy,strcpy 的区别 及memset memcpy memmove源码

    extern void *memcpy(void *dest,void *src,unsigned int count);#include <string.h>   功能:由src所指内存 ...