您的位置:首页 > 其它

UVa Age Sort 11462(排序技巧)

2016-02-26 16:33 495 查看
Age Sort

You are given the ages (in years) of all people of a country with at least 1 year of age. You know thatno individual in that country lives for 100 or more years. Now, you are given a very simple task ofsorting all the ages in ascending order.

Input

There are multiple test cases in the input file. Each case starts with an integer n (0 < n ≤ 2000000), thetotal number of people. In the next line, there are n integers indicating the ages. Input is terminatedwith 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 countrysorted 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 10

Sample Output

1 2 3 4 5

1 2 2 3 3

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define INF 0x3f3f3f3f
#define N 10010
#define ll long long
using namespace std;
int a[110];
int main()
{
int n,m,i,j,k;
while(scanf("%d",&n),n)
{
memset(a,0,sizeof(a));
for(i=0;i<n;i++)
{
scanf("%d",&m);
a[m]++;
}
int tmp=1;
for(i=1;i<=100;i++)
{
for(j=0;j<a[i];j++)
{
if(!tmp)
printf(" ");
tmp=0;
printf("%d",i);
}
}
printf("\n");
}
return 0;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: