-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy path[05]_2.java
47 lines (38 loc) · 981 Bytes
/
[05]_2.java
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
class Node {
public int x;
public int y;
public Node(int x, int y) {
this.x = x;
this.y = y;
}
}
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<Node> data = new ArrayList<Node>();
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
data.add(new Node(x, y));
}
Collections.sort(data, new Comparator<Node>() {
@Override
public int compare(Node a, Node b) {
// x 좌표의 값이 같다면, y의 값을 기준으로 정렬
if (a.x == b.x) {
return Integer.compare(a.y, b.y);
}
// x 좌표의 값이 다르다면, x의 값을 기준으로 정렬
return Integer.compare(a.x, b.x);
}
});
for (Node node: data) {
System.out.println(node.x + " " + node.y);
}
}
}