백준11651: 좌표 정렬하기 2
문제
https://www.acmicpc.net/problem/11651
문제 풀이
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[][] arr = new int[n][2];
for (int i = 0; i < arr.length; i++) {
arr[i][0] = sc.nextInt();
arr[i][1] = sc.nextInt();
}
Arrays.sort(arr, (x, y) -> {
if (x[1] == y[1]) {
return x[0] - y[0];
} else {
return x[1] - y[1];
}
});
for(int i = 0; i < n; i++) {
System.out.println(arr[i][0] + " " + arr[i][1]);
}
}
}
댓글남기기