on
[백준/JAVA] 10989번 : 수 정렬하기 3
[백준/JAVA] 10989번 : 수 정렬하기 3
https://www.acmicpc.net/problem/10989
해당 문제에서는 Scanner를 사용하여 입력받는 경우 시간 초과가 발생합니다.
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { int[] count = new int[10001]; try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { int num = Integer.parseInt(br.readLine()); for(int i = 0; i < num; i++) { count[Integer.parseInt(br.readLine())]++; } StringBuilder sb = new StringBuilder(); for(int i = 1; i < count.length; i++) { while(count[i] > 0) { sb.append(i).append('
'); count[i]--; } } System.out.println(sb); } catch (NumberFormatException e) { } catch (IOException e) { } } }
from http://developernat.tistory.com/44 by ccl(A) rewrite - 2021-09-07 20:00:51