수 정렬하기 3(10989)
수의 범위가 작다면 카운팅 정렬을 사용하여 더욱 빠르게 정렬할 수 있습니다.
Last updated
수의 범위가 작다면 카운팅 정렬을 사용하여 더욱 빠르게 정렬할 수 있습니다.
Last updated
10
5
2
3
1
4
2
3
5
1
71
1
2
2
3
3
4
5
5
7import java.io.*;
import java.util.*;
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 N = Integer.parseInt(br.readLine());
int[] arr = new int[10001];
for(int i=0; i<N; i++){
arr[Integer.parseInt(br.readLine())]++;
}
for(int i=0; i<10001; i++){
while(arr[i]>0){
bw.write(Integer.toString(i));
bw.newLine();
arr[i]--;
}
}
bw.flush();
bw.close();
}
}