본문 바로가기
알고리즘/일반(단순구현)

[백준] 7568번 : 덩치 #Java

by VIPeveloper 2022. 5. 7.
반응형
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

class Person{
    int w,h,rank;

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

public class Main {

    static int [][] dp = new int[15][15];

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int tc = Integer.parseInt(br.readLine());
        Person[] people = new Person[tc];
        for (int i = 0; i < tc; i++) {
            StringTokenizer st = new StringTokenizer(br.readLine()," ");
            int weight = Integer.parseInt(st.nextToken());
            int height = Integer.parseInt(st.nextToken());
            people[i] = new Person(weight,height);
        }
        for (int i = 0; i < tc; i++) {
            int rank = 1;
            Person a = people[i];
            for (int j = 0; j < tc; j++) {
                if(i==j) continue;

                Person b = people[j];
                if(a.w < b.w && a.h < b.h){
                    rank++;
                }
            }
            System.out.print(rank+" ");
        }
    }
}
반응형