본문 바로가기
알고리즘/백준

[JAVA]백준_20124_모르고리즘 회장님 추천 받습니다.

by 박 현 황 2021. 4. 21.

문제링크

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

 

20124번: 모르고리즘 회장님 추천 받습니다

국렬이는 모르고리즘 차기 회장을 빠르게 구해야 한다. 안 그러면 대학원 가서도 회장을 해야 하기 때문이다. 그래서 국렬이는 어떻게든 2020년 연세대학교 프로그래밍 경진대회를 열어서 차기

www.acmicpc.net

 

package BOJ;

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

public class Main_20124 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        Node[] node = new Node[N];
        for(int i=0;i<N;i++){
            StringTokenizer st = new StringTokenizer(br.readLine());
            String name = st.nextToken();
            int score = Integer.parseInt(st.nextToken());
            node[i] = new Node(score,name);
        }

        Arrays.sort(node);
        System.out.println(node[0].name);
    }

    static class Node implements Comparable<Node>{
        int score;
        String name;

        public Node(int score,String name) {
            this.score = score;
            this.name = name;
        }

        @Override
        public int compareTo(Node o) {
            if(this.score == o.score)
                return this.name.compareTo(o.name);
            else
                return o.score-this.score;
        }
    }
}