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

백준 7568 - 덩치 (Java 8)

by latissimus 2022. 2. 28.

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

 

7568번: 덩치

우리는 사람의 덩치를 키와 몸무게, 이 두 개의 값으로 표현하여 그 등수를 매겨보려고 한다. 어떤 사람의 몸무게가 x kg이고 키가 y cm라면 이 사람의 덩치는 (x, y)로 표시된다. 두 사람 A 와 B의 덩

www.acmicpc.net

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int numOfPerson = Integer.parseInt(br.readLine());
        StringTokenizer st;
        List<BodyFrame> frames = new ArrayList<>();

        //입력받아서 리스트에 넣기
        for(int i=0; i<numOfPerson; i++){
            st = new StringTokenizer(br.readLine());
            int height = Integer.parseInt(st.nextToken());
            int weight = Integer.parseInt(st.nextToken());
            frames.add(new BodyFrame(height, weight));
        }
        //덩치 크면 덩치 등수++
        for(int i=0; i<numOfPerson; i++){
            for(int j=0; j<numOfPerson; j++){
                if(i == j) continue;
                if(frames.get(i).height < frames.get(j).height && frames.get(i).weight < frames.get(j).weight){
                    frames.get(i).frameRank++;
                }
            }
        }
        for(int i=0; i<frames.size(); i++){
            System.out.println(frames.get(i).frameRank);
        }
    }
}
class BodyFrame {
    int height;
    int weight;
    int frameRank = 1;
    public BodyFrame(int height, int weight) {
        this.height = height;
        this.weight = weight;
    }
}

댓글