알고리즘

백준 7568번 덩치 (JAVA)

박카스마시며코딩 2023. 11. 29. 14:11

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

 

7568번: 덩치

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

www.acmicpc.net

 

저는 구현을 통해 문제를 해결하였습니다.

구현으로 해당하는 사람이 몇 명보다 덩치가 작은지를 판단하고 이 값에 +1을 해주어 해당 사람의 등수를 찾았습니다.

 

package BOJ.bruteforce;

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

public class BOJ_7568 {
    private static class Info{
        int weight;
        int height;
        public Info(int weight, int height){
            this.weight = weight;
            this.height = height;
        }
    }
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        Info[] infos = new Info[n];
        for(int i = 0 ; i < n ; i++){
            StringTokenizer st = new StringTokenizer(br.readLine());
            int weight = Integer.parseInt(st.nextToken());
            int height = Integer.parseInt(st.nextToken());
            infos[i] = new Info(weight,height);
        }
        int[] cnt = new int[n];
        Arrays.fill(cnt,1);
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                if(infos[i].weight > infos[j].weight && infos[i].height > infos[j].height){
                    cnt[j]++;
                }
            }
        }
        for(int i = 0 ; i < n ; i++){
            System.out.print(cnt[i]+" ");
        }
    }
}

'알고리즘' 카테고리의 다른 글

백준 9935번 문자열 폭발 (JAVA)  (0) 2023.12.01
백준 1940번 주몽 (JAVA)  (1) 2023.11.30
백준 2343번 기타 레슨 (JAVA)  (0) 2023.11.28
백준 3273번 두 수의 합 (JAVA)  (2) 2023.11.27
백준 1141번 접두사 (JAVA)  (0) 2023.11.26