

-Code
import java.util.*;
import java.io.*;
public class BOJ20949 {
public static void main(String[] args) throws IOException {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
// ppi와 index를 저장
int[][] ppiAndIdxArray = new int[n][2];
for (int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int w = Integer.parseInt(st.nextToken());
int h = Integer.parseInt(st.nextToken());
int ppi = w * w + h * h;
ppiAndIdxArray[i] = new int[] { ppi, i };
}
// ppi가 같으면 index 오름차순 아니면 ppi 내림차순
Arrays.sort(ppiAndIdxArray, (o1, o2) -> {
if (o1[0] == o2[0]) {
return o1[1] - o1[1];
}
return o2[0] - o1[0];
});
// 출력
for (int[] ppiAndIds : ppiAndIdxArray) {
System.out.println(ppiAndIds[1] + 1);
}
}
}'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
| [프로그래머스/Java] 피로도 (0) | 2026.01.06 |
|---|---|
| [백준/Java] 16139번 인간-컴퓨터 상호작용 (0) | 2026.01.06 |
| [백준/Java] 3060번 욕심쟁이 돼지 (0) | 2026.01.06 |
| [프로그래머스/Java] 소수 찾기 (0) | 2026.01.06 |
| [프로그래머스/Java] k진수에서 소수 개수 구하기 (0) | 2026.01.05 |