Uva-------(11462) Age Sort(计数排序)
B |
Age Sort Input: Standard Input Output: Standard Output |
---|
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 file. Each case starts with an integer n (0<n<=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 Output for Sample Input
5 3 4 2 1 5 5 2 3 2 3 1 0 |
1 2 3 4 5 1 2 2 3 3 |
---|
Note: The memory limit of this problem is 2 Megabyte Only.
Problem Setter: Mohammad Mahmudur Rahman
Special Thanks: Shahriar Manzoor
数据大,内存小,而数据值的范围有限,适合运用计数排序求解...
代码:
1 #include<cstdio>
2 #include<cstring>
3 /*计数排序*/
4 int main()
5 {
6 int n,hash[101],val;
7 while(~scanf("%d",&n)&&n)
8 {
9 memset(hash,0,sizeof(hash));
10 for(int i=0;i<n;i++)
11 {
12 scanf("%d",&val);
13 hash[val]++;
14 }
15 int flag=true;
16 for(int i=0; i<=100; i++)
17 {
18 for(int j=1;j<=hash[i];j++)
19 {
20 if(flag)
21 {
22 printf("%d",i);
23 flag=false;
24 }
25 else printf(" %d",i);
26 }
27 }
28 puts("");
29 }
30 return 0;
31 }
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 带你入门Linux中size命令的6个例子
- 详解CentOS重启后resolv.conf被重置的解决方案
- scRNA-seq Clustering quality control(二)
- ubuntu环境下安装memcache及启动的方法
- Linux下批量修改服务器用户密码方法步骤
- Linux 常用文本处理命令和vim文本编辑器
- centos7利用yum安装lnmp的教程(linux+nginx+php7.1+mysql5.7)
- linux根据进程号PID查找启动程序的全路径
- linux服务器安装PHP扩展zip,zlib方法
- Lamp环境下设置绑定apache域名的方法分析
- Linux杀不死的进程之CPU使用率700%解决方法
- 解读Linux下ip命令展示的网络连接信息
- Apache ActiveMQ任意文件写入漏洞(CVE-2016-3088)复现
- Linux环境使用g++编译C++方法总结
- linux命令实现音频格式转换和拼接的方法