Updated:

1. 문제 링크

https://www.acmicpc.net/problem/10989

2. 사용 알고리즘

정렬

3. 풀이

1부터 10,000까지의 배열에 count를 누적한 후 count 만큼 반복해서 출력

4. 소스 코드

4-1. C++

https://github.com/dev-aiden/problem-solving/blob/main/boj/10989.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

using namespace std;

int arr[10003];

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n; for (cin >> n; n--;) {
        int num; cin >> num;
        ++arr[num];
    }
    for (int i = 1; i <= 10000; ++i) {
        for (int j = 0; j < arr[i]; ++j) {
            cout << i << "\n";
        }
    }
    return 0;
}

4-2. JAVA

https://github.com/dev-aiden/problem-solving/blob/main/boj/10989.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    static int[] arr = new int[10003];

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for(int i = 0; i < n; ++i) {
            int num = Integer.parseInt(br.readLine());
            ++arr[num];
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= 10000; ++i) {
            for (int j = 0; j < arr[i]; ++j) {
                sb.append(i).append("\n");
            }
        }
        System.out.println(sb);
    }
}

Updated:

Leave a comment