-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_11651
More file actions
58 lines (41 loc) · 1.4 KB
/
BAEKJOON_11651
File metadata and controls
58 lines (41 loc) · 1.4 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
import java.io.*;
import java.util.*;
public class Main {
static class Num{
private int x;
private int y;
public Num(int x, int y) {
this.x = x;
this.y = y;
}
}
public static void main(String[] args) throws IOException {
//y 좌표가 증가하는 순서로
//y좌표가 같으면 x좌표가 증가하는 순서로 정렬후 출력.
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw =new BufferedWriter(new OutputStreamWriter(System.out));
List<Num> list = new ArrayList<>();
int N = Integer.parseInt(br.readLine());
for(int i=0; i<N; i++){
StringTokenizer st= new StringTokenizer(br.readLine());
int x= Integer.parseInt(st.nextToken());
int y= Integer.parseInt(st.nextToken());
list.add(new Num(x,y));
}
Collections.sort(list,new Comparator<Num>(){
@Override
public int compare(Num n1, Num n2){
if(n1.y > n2.y){
return 1;
}else if(n1.y == n2.y){
return n1.x-n2.x;
}else{
return -1;
}
}
});
for(int i=0; i<list.size(); i++){
System.out.println(list.get(i).x+" "+list.get(i).y);
}
}
}