백준 7568번

김경욱·2025년 8월 29일

백준

목록 보기
68/121

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

import java.util.*;

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[] rank = new int[N];

    int[] weight = new int[N];
    int[] height = new int[N];


   for (int i = 0 ; i < N; i++)
    {
        StringTokenizer st = new StringTokenizer(br.readLine());
        weight[i] = Integer.parseInt(st.nextToken());
        height[i] = Integer.parseInt(st.nextToken());

    }



  for (int i = 0; i < N; i++)
    {
        int count = 1;
        for (int j = 0; j < N; j++)
        {
            if (height[i] < height[j] && weight[i] < weight[j])
            {
                count++;
            }
          


        }

        rank[i] = count;
    }

    for (int i : rank) {
        System.out.print(i+" ");
    }









}

}

지금 이렇게 풀면 백준에는 제출이 되고

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

import java.util.*;

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[] rank = new int[N];

    int[] weight = new int[N];
    int[] height = new int[N];


   for (int i = 0 ; i < N; i++)
    {
        StringTokenizer st = new StringTokenizer(br.readLine());
        weight[i] = Integer.parseInt(st.nextToken());
        height[i] = Integer.parseInt(st.nextToken());

    }



  for (int i = 0; i < N; i++)
    {
        int count = N;
        for (int j = 0; j < N; j++)
        {
            if (height[i] > height[j] && weight[i] > weight[j])
            {
                count--;
            }
            if (height[i] > height[j] && weight[i] < weight[j])
            {
                count--;
            }
            if (height[i] < height[j] && weight[i] > weight[j])
            {
                count--;
            }

        }

        rank[i] = count;
    }

    for (int i : rank) {
        System.out.print(i+" ");
    }









}

}

이렇게 등수를 마지막 등수에서 하나씩 +하는 방식으로는 답이 우연히 나오지만 결국에는 값이 나오지 않는다. 문제를 풀때는 문제에서 제시하는 대로 코드를 작성하는게 맞는 것 같다.

0개의 댓글