-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNo_11651.java
More file actions
69 lines (59 loc) · 1.91 KB
/
No_11651.java
File metadata and controls
69 lines (59 loc) · 1.91 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
Problem_11651_좌표 정렬하기 2
https://www.acmicpc.net/problem/11651
*/
import java.io.*;
import java.util.*;
public class No_11651 {
private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
private static List<coordinates> list = new ArrayList<>();
public static void main(String[] args) throws IOException {
input();
Collections.sort(list, new Comparator<coordinates>() {
@Override
public int compare(coordinates o1, coordinates o2) {
if (o1.getY() > o2.getY()) {
return 1;
} else if (o1.getY() < o2.getY()) {
return -1;
} else {
if (o1.getX() > o2.getX()) {
return 1;
} else {
return -1;
}
}
}
});
for (coordinates i : list) {
bw.append(i.getX() + " " + i.getY() + "\n");
}
bw.flush();
bw.close();
}
// 좌표 입력 함수
private static void input() throws IOException {
int len = Integer.parseInt(br.readLine());
StringTokenizer st;
for (int i = 0; i < len; i++) {
st = new StringTokenizer(br.readLine(), " ");
list.add(new coordinates(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())));
}
br.close();
}
private static class coordinates {
private int x;
private int y;
private coordinates(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
}
}