알고리즘/백준
[백준7568]- 덩치- JAVA
놀이방사장님
2023. 11. 25. 00:00
728x90
반응형
안녕하세요 놀이방 사장입니다.
이번 포스팅은 백준 7568 덩치 포스팅입니다.
7568번: 덩치
우리는 사람의 덩치를 키와 몸무게, 이 두 개의 값으로 표현하여 그 등수를 매겨보려고 한다. 어떤 사람의 몸무게가 x kg이고 키가 y cm라면 이 사람의 덩치는 (x, y)로 표시된다. 두 사람 A 와 B의 덩
www.acmicpc.net
덩치는 각각의 사람을 키와 몸무게를 비교해서 두 개가 더 작으면 순위가 밀리게 하면 됩니다.
그렇게 해서 로직을 짜면 밑에 처럼 됩니다.
두개의 값이 동일하거나 하나는 크고 하나는 작으면 그냥 카운트하지 않으면 됩니다.
package me.joyeonggyu;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
public class Main{
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
int[] key = new int[n];
int[] MoM = new int[n];
int[] count = new int[n];
for(int i =0; i< n; i++){
String str = br.readLine();
String[] split = str.split(" ");
MoM[i] = Integer.parseInt(split[0]);
key[i] = Integer.parseInt(split[1]);
}
for(int i=0; i<n; i++){
for(int j=i+1; j<n; j++){
if(key[i] > key[j] && MoM[i] > MoM[j]){
count[j]++;
}else if(key[i] < key[j] && MoM[i] < MoM[j]){
count[i]++;
}
}
}
for(int i : count){
bw.write(String.valueOf(i+1)+" ");
bw.flush();
}
br.close();
bw.close();
}
}
혼자 못 푸실 경우에는 풀이를 참조하고 코드를 보는 것도 좋은 방법이라고 생각합니다
다들 열심히 공부합시다!
반응형