hbmy周赛1--A
2015-06-07 11:44
232 查看
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 1
0
Sample Output
1 2 3 4 5
1 2 2 3 3
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int compare(int x, int y)
{
return x < y;
}
int a[2000010];
int main()
{
int n;
while (scanf("%d",&n) && n)
{
for (int i=0; i<n; i++)
scanf("%d",&a[i]);
sort(a,a+n,compare);
printf("%d",a[0]);
for (int i=1; i<n; i++)
printf(" %d",a[i]);
printf("\n");
}
return 0;
}
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 1
0
Sample Output
1 2 3 4 5
1 2 2 3 3
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int compare(int x, int y)
{
return x < y;
}
int a[2000010];
int main()
{
int n;
while (scanf("%d",&n) && n)
{
for (int i=0; i<n; i++)
scanf("%d",&a[i]);
sort(a,a+n,compare);
printf("%d",a[0]);
for (int i=1; i<n; i++)
printf(" %d",a[i]);
printf("\n");
}
return 0;
}
相关文章推荐
- Storm入门之第一章
- 25岁开始编程学习
- 关于 释放堆内存出错的 问题
- 如何搭建X5本地应用打包服务器
- hbmy周赛1--A
- 练习作品8:批量生产卡密
- Android中的五大布局
- Codeforces #306 Div 2 简要题解
- Android R.java文件丢失
- 如何利用好AD查询工具
- Spring MVC 教程
- ListView Button ImageView 里应用selector选择器切换图片并保持住
- Linux内核与驱动开发学习总结:主设备号和次设备号(二)
- Linux内核与驱动开发学习总结:DMA与中断(一)
- EM (Expectation Maximization) 算法理解
- [准备篇4]VMWare搭建Openstack——配置OpenStack镜像源
- URAL 1224. Spiral (规律)
- ThinkPHP隐藏index.php出现No input file specified的解决方法
- 【leetcode】Count Primes
- [镜像制作]VMWare搭建Openstack——Ubuntu怎么制作最小的镜像文件(二)