씨름 선수

Changwook Yang·2023년 1월 28일

알고리즘 연습

목록 보기
16/41

N명이 지원하였고
A라는 지원자가 다른 모든 지원자보다 키와 몸무게가 모두 낮으면 선발에서 탈락된다.

ex)

5
172 67
183 65
180 70
170 72
181 60

(183, 65), (180, 70), (170, 72) 가 선발됩니다.
(181, 60)은 (183, 65)보다 키와 몸무게 모두 낮기 때문에 탈락이고,
(172, 67)은 (180, 70) 때문에 탈락입니다.

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Person {
    int height;
    int weight;

    public Person(int height, int weight) {
        this.height = height;
        this.weight = weight;
    }
}

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();

        List<Person> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int height = scanner.nextInt();
            int weight = scanner.nextInt();
            list.add(new Person(height, weight));
        }

        int cnt = 0;
        for (Person target : list) {
            boolean isEnough = true;
            for (Person other : list) {
                if (target.height < other.height && target.weight < other.weight) {
                    isEnough = false;
                    break;
                }
            }
            if (isEnough) cnt++;
        }

        System.out.println(cnt);
    }
}
profile
멋있는 백엔드 개발자 / 꾸준히 의미있게!

0개의 댓글