https://www.acmicpc.net/problem/10989
: 배열을 이용해서 빈도수를 센 후 출력하는 방식
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Boj_10989 {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
int[] cnt = new int[10001];
for(int i=0; i<N; i++){
cnt[Integer.parseInt(br.readLine())]++;
}
for(int i=0; i<10001; i++){
for(int j=0; j<cnt[i]; j++){
bw.write(i+"\n");
}
}
bw.flush();
}
}
Scanner
와 println
보다는 BufferedReader
와 BufferedWriter
를 쓰는게 좋다.