boj 1946 신입사원

신준호·2023년 10월 12일
0
post-thumbnail

문제링크

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

문제 풀이

정렬 문제이다. 서류 점수로 오름차순으로 정렬을 한 다음 2등 부터 면접 점수를 1등 면접 점수를 최솟값으로 지정하고 비교하면서 더 작으면 최솟값을 update하여 비교한다.
더작으면 그 사람은 합격이다.

전체 코드

package BOJ;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class 신입사원 {
    static class Score implements Comparable<Score> {
        int a,b;
        public Score(int a, int b) {
            this.a = a;
            this.b = b;
        }
        @Override
        public int compareTo(Score s) {
            return Integer.compare(this.a,s.a);
        }
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int T = Integer.parseInt(br.readLine());
        for (int tc = 0; tc < T; tc++) {
            int n = Integer.parseInt(br.readLine());
            List<Score> list = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                StringTokenizer st = new StringTokenizer(br.readLine());
                int a = Integer.parseInt(st.nextToken());
                int b = Integer.parseInt(st.nextToken());
                list.add(new Score(a, b));
            }
            Collections.sort(list);
            int min = list.get(0).b;
            int anw = 1;
            for (int i = 1; i < n; i++) {
                if (list.get(i).b < min) {
                    anw++;
                    min = list.get(i).b;
                }
            }
            System.out.println(anw);

        }
    }
}
profile
개발 공부 일지

0개의 댓글