포인트! : 사람들의 몸무게와 키를 입력하여 덩치 순서 출력
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);
}
}
아직 알고리즘을 생각해 내는 것이 쉽지 않다..
'알고리즘' 카테고리의 다른 글
[백준] 2798 : 블랙잭 <JAVA> (0) | 2021.01.13 |
---|---|
[백준] 2231 : 분해합 <JAVA> (0) | 2021.01.13 |
[알고리즘] Brute force (브루트 포스) (0) | 2021.01.10 |
[백준] 11729 : 하노이 탑 이동 순서 <JAVA> (0) | 2021.01.08 |
[백준] 2447 : 별 찍기 <JAVA> (0) | 2021.01.08 |