[백준] 7568 : 덩치 <JAVA>

 

포인트! : 사람들의 몸무게와 키를 입력하여 덩치 순서 출력

 

1. 사람들 수 입력

2. 사람들 몸무게와 키 입력

3. 사람들의 덩치 순서 구하기

  • 방법: 자신보다 몸무게와 키가 큰 사람들의 수 +1 = 자신의 덩치 순위

 

4. 덩치 순서 출력

 

 

import java.util.Scanner;

public class Main {
 
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[][] data; int size;

    //step1 : Enter the number of people
    size = sc.nextInt();
    if(size < 1)
      return;
    data = new int[size][3];
    

    //step2 : Enter people's weight and height
    for(int i =0 ; i< size ; i++ ){
      data[i][0] = sc.nextInt();
      data[i][1] = sc.nextInt();
      data[i][2] = 0;
    }

    //step3 : Ranking
    for(int h=0;h<size;h++){
      int count=0;
      for(int s=0;s <size;s++){
        if(s == h)
          continue;
        if(data[h][0] < data[s][0] && data[h][1] < data[s][1])
          count++;
      }
      data[h][2] = count+1;
    }

    //step4 : Print the ranking
    StringBuilder sb = new StringBuilder();
    for(int p =0; p< size ;p++){
      sb.append( data[p][2]);
      if(p+1 != size)
        sb.append(" ");
    }
    System.out.println(sb);
  }
}

 

아직 알고리즘을 생각해 내는 것이 쉽지 않다..