21.08.26 기록

최대 1 분 소요

백준 알고리즘 11651 풀이

🎆나의 풀이(메모리 50.5MB, 시간 760ms로 통과)

-#11650 해설과 같은 알고리즘으로 풀이했다.
-#11651 해설도 111650의 해설로 링크를 안내한다.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class B11651 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());

        StringTokenizer st;
        int[][] count = new int[N][2];
        for(int i = 0; i < N; i++) {
            st = new StringTokenizer(br.readLine(), " ");
            count[i][0] = Integer.parseInt(st.nextToken());
            count[i][1] = Integer.parseInt(st.nextToken());
        }

        Arrays.sort(count, (e1, e2) -> {
            if(e1[1] == e2[1]) { return e1[0] - e2[0]; }
            else { return e1[1] - e2[1]; }
        });

        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < N; i++) {
            sb.append(count[i][0]).append(" ").append(count[i][1]).append("\n");
        }
        System.out.println(sb);
    }
}

카테고리:

업데이트: