
배운점
시간초과 때문에 자꾸 오류가 났다.
BufferedWriter를 사용하는 법을 복습했다.
카운팅 소트를 어떻게 사용하는 지 알게되었다.
풀이
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
|
package 정렬;
import java.io.*;
public class 수_정렬하기3 {
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 n = Integer.parseInt(br.readLine());
int [] nums = new int[n];
int [] count = new int[10001];
int cnt = 0;
for (int i = 0; i <n ; i++) {
nums[i] = Integer.parseInt(br.readLine());
}
for(int i: nums){
count[i] ++;
}
for(int i= 0;i<10001;i++) {
if (count[i]> 0) {
for (int j = 0; j < count[i]; j++) {
bw.write(i+"\n");
}
}
}
bw.close();
br.close();
}
}
|
cs |
'IT > 알고리즘' 카테고리의 다른 글
백준 15650 N과 M(2) (0) | 2020.02.20 |
---|---|
백준 15649 N 과M(1) (0) | 2020.02.20 |
백준11650 좌표정렬하기 (0) | 2020.02.16 |
백준 1427 소트인사이드 (1) | 2020.02.16 |
백준 11729 하노이탑 이동순서 문제 (0) | 2020.02.15 |