Repository navigation
Expand file tree
/
Copy pathBOJ_10989.java
More file actions
63 lines (45 loc) · 1.49 KB
/
Copy pathBOJ_10989.java
File metadata and controls
63 lines (45 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package baekjoon.silver;
import java.io.*;
public class BOJ_10989 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
// 수의 범위 : 0 ~ 10,000
// 입력 : N개
int N = Integer.parseInt(br.readLine());
// *** Counting Sort 를 이용한 방법 ***
int[] array = new int[N];
int[] counting = new int[10001];
int[] result = new int[N];
for (int i = 0; i < N; i++) {
array[i] = Integer.parseInt(br.readLine());
}
for (int i = 0; i < N; i++) {
counting[array[i]]++;
}
for (int i = 1; i < counting.length; i++) {
counting[i] += counting[i-1];
}
for (int i = N - 1; i >= 0; i--) {
int value = array[i];
counting[value]--;
result[counting[value]] = value;
}
// 출력
for (int i = 0; i < result.length; i++) {
bw.write(result[i] + "\n");
}
/* *** Arrays.sort() 를 이용한 방법 ***
int[] array = new int[N];
for (int i = 0; i < N; i++) {
array[i] = Integer.parseInt(br.readLine());
}
Arrays.sort(array);
for (int i = 0; i < N; i++) {
bw.write(array[i] + "\n");
}
*/
bw.flush();
bw.close();
}
}