본문 바로가기
[Public] 컴퓨터공학/UVA

[UVA] 11362 Age Sort

by 차출발 2011. 7. 28.
반응형

 

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


카운트 소트를 이용하면 쉽게 구할 수 있다.

직접 해보시길 ^^


소스 코드

#include <stdio.h>

#define MAX 2000000

int nData[MAX];

int main()

{

        int nInput, i, j;

        while(1)

        {

               int nAge[100] = {0, };

               scanf("%d", &nInput);

               if(!nInput)break;

               for(i=0 ; i<nInput ; i++)

               {

                       scanf("%d", &nData[i]);

 

                       nAge[nData[i]]++;

               }

               for(i=0 ; i<100 ; i++)

               {

                       if(nAge[i])

                       {

                              for(j=0 ; j<nAge[i] ; j++)

                                      printf("%d", i);

                       }

               }

               printf("\n");

        }

        return 0;

}


'[Public] 컴퓨터공학 > UVA' 카테고리의 다른 글

[UVA] 100 3n+1 problem  (0) 2011.07.25
[UVA] 575 Skew Binary  (0) 2010.04.26
[UVA] 10019 Funny Encryption Method  (0) 2010.04.18