九度0J 1374 所有员工年龄排序

题目地址:http://ac.jobdu.com/problem.php?pid=1374

题目描述:

公司现在要对所有员工的年龄进行排序,因为公司员工的人数非常多,所以要求排序算法的效率要非常高,你能写出这样的程序吗?

输入:

输入可能包含多个测试样例,对于每个测试案例,

输入的第一行为一个整数n(1<= n<=1000000):代表公司内员工的人数。

输入的第二行包括n个整数:代表公司内每个员工的年龄。其中,员工年龄age的取值范围为(1<=age<=99)。

输出:

对应每个测试案例,

请输出排序后的n个员工的年龄,每个年龄后面有一个空格。

样例输入:
543 24 12 57 45
样例输出:
12 24 43 45 57
#include <stdio.h>
 
int main(void){
    int n;
    int staff[100];
    int age;
    int i;
 
    while (scanf ("%d", &n) != EOF){
        for (i=0; i<100; ++i)
            staff[i] = 0;
        while (n-- > 0){
            scanf ("%d", &age);
            ++staff[age];
        }
        for (i=0; i<100; ++i){
            while (staff[i]-- > 0){
                printf ("%d ", i);
            }
        }
        putchar ('
');
    }
 
    return 0;
}
原文地址:https://www.cnblogs.com/liushaobo/p/4373822.html