기수 정렬 예제 - 1
Last updated
Last updated
n(정렬할 수 개수)
count(카운팅 정렬 리스트)
for n 반복:
count 리스트에 현재 수에 해당하는 index 값 1 증가
for i 0 ~ 10000까지:
if count[i] 값이 0이 아니면
해당 값만큼 i 반복 출력import sys
input = sys.stdin.readline
print = sys.stdout.write
n = int(input())
count = [0] * 10001
for i in range(n):
count[int(input())] += 1
result = []
for i in range(10001):
if count[i] != 0:
for _ in range(count[i]):
print(str(i) + "\n")import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[] count = new int[10001];
for (int i = 0; i < n; i++) {
count[Integer.parseInt(br.readLine())]++;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10001; i++) {
while (count[i] > 0) {
sb.append(i).append("\n");
count[i]--;
}
}
System.out.println(sb);
}
}