-
Notifications
You must be signed in to change notification settings - Fork 5
/
좌표정렬하기.java
37 lines (36 loc) · 967 Bytes
/
좌표정렬하기.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
package baekjoon;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
class location{
int x ,y;
public location(int x, int y){
this.x =x;
this.y =y;
}
}
public class 좌표정렬하기 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
location [] lc = new location[n];
for (int i=0; i<n; i++){
int x = sc.nextInt();
int y = sc.nextInt();
lc[i] = new location(x,y);
}
Arrays.sort(lc, new Comparator<location>() {
@Override
public int compare(location o1, location o2) {
if (o1.x == o2.x){
return o1.y - o2.y;
}else {
return o1.x - o2.x;
}
}
});
for (location c : lc){
System.out.println(c.x+" "+c.y);
}
}
}