ACM比赛(11462 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 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;
}
时间: 2024-10-11 00:39:51

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

UVA之11462 - 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.

[2016-03-19][UVA][11462][Age Sort]

时间:2016-03-19 20:22:57 星期六 题目编号:[2016-03-19][UVA][11462][Age Sort] 题目大意:给定n个数字,输出排序后的数据, 分析:n<=2*1E6,多组数据,所以不能直接读取然后排序,这里的数据内容范围是1~100,则可以通过计数的方式来统计,或者自己编写读取和输出的函数来优化 方法2 #include <cstdio> #include <cstring> using namespace std; typedef lon

UVA - 11462 - Age Sort (高效算法!!)

11462 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 ascendi

11462 - Age Sort

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2457 题目大意: 给出数组年龄数据,每组有n(0<n<=2000000)个数据,要求按从小到大的顺序进行排列,需要注意的是输入的数据有可能比较多,所以需要使用更快的IO 案例: Sample Input 5 3 4 2 1 5 5 2 3 2 3 1 0 Sample

11462 Age Sort(计数排序)

内存不够用,用计数排序可以解决问题. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include<map> #include<set> #include<vector> #include<list> #include<

COGS 1406. 邻居年龄排序[Age Sort,UVa 11462]

★   输入文件:AgeSort.in   输出文件:AgeSort.out   简单对比时间限制:1 s   内存限制:2 MB [题目描述] Mr.Zero(CH)喜闻乐见地得到了一台内存大大增强的 OI型 Apple Ⅱ,可以运行C,C++,和Pascal!为了炫耀这台高端的计算机,Mr.Zero决心将邻居们的年龄(0≤Age[i]≤120)统计后进行统计.但是,古董终究是古董,Mr.Zero拥有最多n个邻居(n≤2,400,000)但是计算机所能运行程序时的内存限制竟然达到了2MB.请你

ACM Age Sort排序

Description 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 a

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

A -- simple math problem Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 SAMPLE INPUT 5 20 1314 SAMPLE OUTPUT 5 21 1317 SOLUTION “玲珑杯”ACM比赛 Round #19 题目链接:http://www.ifrog.cc/acm/problem/1145 分析: 这个题解是官方写法,官方代码如下: 1 #include <iostream>

ACM比赛经验

ACM比赛经验: 推荐此篇文章打印,与模板放在一起. 1. 比赛中评测会有些慢,偶尔还会碰到隔10分钟以上才返回结果的情况,这段时间不能等结果,必须开工其他题,如果WA,两道题同时做.交完每道题都要先打印. 2. 比赛时发的饭不是让你当时就吃的,那是给你赛后吃的.基本上比赛中前几名的队都没人吃,除非领先很多. 3. 很多选手,尤其是第一次参加比赛的,到一个新环境,全当旅游了,参观的参观,找同学的找同学,玩玩乐乐就把正事抛到脑后了,结果比赛自然没什么好成绩,这样的例子太多了.所以到参赛地后要时刻不