계수정렬 알고리즘을 이용해야 주어진 메모리, 시간에 안에 할 수 있다.
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int repeat_count = Integer.parseInt(br.readLine());
int[] array = new int[10001];
for (int i = 0; i < repeat_count; i++) {
array[Integer.parseInt(br.readLine())]++;
}
for (int i = 1; i <= 10000; i++) {
if (array[i] != 0) {
for (int j = 0; j < array[i]; j++) {
bw.write(i + "\n");
}
}
}
bw.flush();
}
}
'CodingTest' 카테고리의 다른 글
[CodingTest] 백준 1676번 (0) | 2024.04.17 |
---|---|
[CodingTest] 백준 1874번 (0) | 2024.04.17 |
[CodingTest] 백준 9012번 (0) | 2024.04.16 |
[CodingTest] 백준 1018번 (0) | 2024.04.15 |
[CodingTest] 백준 1654번 (0) | 2024.04.13 |