코딩테스트/백준
[Dev-Ping9] 백준 7568번 - 덩치 (Java)
DevPing9_
2021. 12. 14. 11:56


# 문제 설명
덩치 등수를 구하기 위해서는 한 사람이 그 외에 모든 사람과 비교를 해야 하므로,
그저 문제를 잘 이해하고, 그에 따른 구현능력이 필요한 문제인 것 같다.
# 코드 구현
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main{
static int[][] human;
static void printArr(int[][] arr){
for(int i=0;i<arr.length;i++){
for(int j=0;j<arr[0].length;j++){
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
static boolean amIBigger(int x, int y, int p ,int q){
if(x>p && y>q){
return true;
}
else if(p>x && q>y){
return false;
}
return true;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int times = Integer.parseInt(br.readLine());
human = new int[times][3];
StringTokenizer st;
for(int i=0; i<times; i++){
st = new StringTokenizer(br.readLine(), " ");
human[i][0]=Integer.parseInt(st.nextToken());
human[i][1]=Integer.parseInt(st.nextToken());
human[i][2]=times;
}
// printArr(human);
for(int i=0; i<times;i++){ //1명당 n-1번 비교
for(int[] person : human){
if(person == human[i]) continue;
if(amIBigger(person[0], person[1], human[i][0], human[i][1])){
person[2]--;
}
}
}
// printArr(human);
for(int i=0;i<times;i++){
sb.append(human[i][2]).append(" ");
}
System.out.println(sb);
}
}
728x90