[백준-Java] 브루스포스 3번

RedPanda·2021년 11월 5일
0

[알고리즘] Java

목록 보기
3/16

7568번) 덩치

이번 문제는 키와 몸무게를 연관지어서 등수를 매기는 것이다.

키가 작아도 몸무게가 더 나간다면 둘은 같은 등수를 가질 수 밖에 없다.

그렇다면 키와 몸무게 모두 작다면 순위가 밀리게 된다.

따라서 arr[확인할 index][0 and 1] < arr[순환할 index][0 and 1]을 조건으로 풀면 완성된다.

확인할 index를 겉 반복문, 순환할 index를 속 반복문으로 지정해두는 것이 핵심이다.

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        int[][] arr = new int[N][2];
        int[] grade = new int[N];
        int max = 0;
        for(int i = 0; i < N; i++){
            String dungChi = br.readLine();
            arr[i][0] = Integer.parseInt(dungChi.split(" ")[0]);
            arr[i][1] = Integer.parseInt(dungChi.split(" ")[1]);
        }
        for(int i = 0; i < N; i++){
            int rank = 1;
            for(int j = 0; j < N; j++){
                if(arr[i][1] < arr[j][1] && arr[i][0] < arr[j][0]){
                    rank++;
                }
            }
            System.out.print(rank + " ");
        }
    }
}
profile
끄적끄적 코딩일기

0개의 댓글