Skip to content

20.12.09 [백준] 10989 수 정렬하기 3 #99

Description

@blossun
  • 수는 10,000보다 작거나 같은 자연수
  • 중복 가능

아이디어

  • Counting Sort

어려운점 & 실수

  • 중복이 가능하므로 boolean 배열이 아닌 int형 배열로 몇번 나왔는지 체크해서 나온 수 만큼 출력해줌
  • 자연수이므로 음수를 신경쓰지 않아도 됨!! (처음에 음수가 들어오는 줄 알고 20002로 잡았었다.)

정답

importjava.io.BufferedReader;
importjava.io.IOException;
importjava.io.InputStreamReader;
publicclassN10989 {
publicstaticvoidmain(String[] args) throwsIOException {
BufferedReaderbr = newBufferedReader(newInputStreamReader(System.in));
StringBuildersb = newStringBuilder();
intN = Integer.parseInt(br.readLine());
int[] input = newint[10002];
for (inti = 0; i < N; i++) {
intnum = Integer.parseInt(br.readLine());
input[num]++;
}
for (inti = 0; i < 10002; i++) {
for (intj = 0; j < input[i]; j++) {
sb.append(i).append('\n');
}
}
System.out.println(sb);
}
}

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions