Uva-------(11462) Age Sort(计数排序)
2014-08-05 00:26
573 查看
B | Age Sort Input: Standard Input Output: Standard Output |
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 |
[align=center][/align]
Problem Setter: Mohammad Mahmudur Rahman
Special Thanks: Shahriar Manzoor
数据大,内存小,而数据值的范围有限,适合运用计数排序求解...
代码:
#include<cstdio> #include<cstring> /*计数排序*/ int main() { int n,hash[101],val; while(~scanf("%d",&n)&&n) { memset(hash,0,sizeof(hash)); for(int i=0;i<n;i++) { scanf("%d",&val); hash[val]++; } int flag=true; for(int i=0; i<=100; i++) { for(int j=1;j<=hash[i];j++) { if(flag) { printf("%d",i); flag=false; } else printf(" %d",i); } } puts(""); } return 0; }
View Code
相关文章推荐
- Age Sort UVA - 11462(计数排序)
- UVA 11462 Age Sort 计数排序 .
- UVA11462-(Age sort)(计数排序)
- UVA11462 Age Sort【基数排序/桶排序/计数排序】
- uva11462 Age Sort ——计数排序
- uva11462(Age sort)(计数排序)
- UVa 11462 Age Sort (计数排序&快速输入输出)
- UVa 11462 - Age Sort (桶排序)
- 指南第一章 例题 17 UVA 11462 Age Sort(桶排序)
- uva 11462 Age Sort
- uva 11462 Age Sort
- 【UVA 11462】 Age Sort(基数排序)
- uva_11462_Age Sort(sort)
- UVA - 11462 Age Sort
- Age Sort(UVa 11462)
- UVA 11462 Age Sort(IO优化)
- UVA 11462 - Age Sort
- UVa 11462 - Age Sort
- UVA 11462 Age Sort
- UVa Age Sort 11462(排序技巧)