본문 바로가기
Problem Solving/Baekjoon

[백준] 22966 가장 쉬운 문제를 찾는 문제 - Implementation / Java

by graycode 2025. 9. 26.

 문제 링크

https://www.acmicpc.net/problem/22966

 

 풀이 코드

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        Pair[] arr = new Pair[Integer.parseInt(br.readLine())];
        for (int i = 0; i < arr.length; i++) arr[i] = new Pair(br.readLine());
        Arrays.sort(arr);

        bw.write(arr[0].s);
        bw.flush();
    }

    private static class Pair implements Comparable<Pair> {
        String s;
        int i;

        Pair(String s) {
            int idx = s.indexOf(' ');
            this.s = s.substring(0, idx);
            this.i = Integer.parseInt(s.substring(idx + 1));
        }

        @Override
        public int compareTo(Pair o) {
            return this.i - o.i;
        }
    }

}

댓글