๋ฌธ์
ํ์ด
- comparator ๋ง๋ค์ด์ ํ์ด์ฃผ๋ฉด๋ฉ๋๋ค.
- ์ต๋ช
ํด๋์ค์ด๊ธฐ ๋๋ฌธ์ ๋๋ค์์ผ๋ก ์ค๋ฒ๋ผ์ด๋ ๋ฉ์๋๋ฅผ ๊ฐ๋จํ๊ฒ ๊ตฌํํด์คฌ์ต๋๋ค.
์ฝ๋
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Bj11651_AlignCoordinate2 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[][] arr = new int[n][2];
for(int i = 0; i< n; i++) {
String[] s = br.readLine().split(" ");
arr[i][0] = Integer.parseInt(s[0]);
arr[i][1] = Integer.parseInt(s[1]);
}
Arrays.sort(arr,(e1,e2) -> {
if(e1[1] ==e2[1]) {
return e1[0] - e2[0];
} else {
return e1[1] - e2[1];
}
});
for(int i = 0 ; i < n ; i ++){
System.out.println(arr[i][0] + " " + arr[i][1]);
}
}
}