Problem Solving
[BOJ] 11650 JAVA
지옹
2024. 12. 9. 13:38
문제
https://www.acmicpc.net/problem/11650
코드
import java.util.*;
public class Main {
public static final int MAX_N = 1000;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int n = sc.nextInt();
List<Coord> arr = new ArrayList<>();
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
arr.add(new Coord(x, y));
}
arr.sort(comp);
for (Coord coord : arr) {
sb.append(coord.x).append(" ").append(coord.y).append('\n');
}
System.out.println(sb);
}
static Comparator<Coord> comp = new Comparator<Coord>() {
@Override
public int compare(Coord o1, Coord o2) {
if(o1.x == o2.x) return o1.y-o2.y;
return o1.x-o2.x;
}
};
public static class Coord {
int x, y;
public Coord(int x, int y) {
this.x = x;
this.y = y;
}
}
}