๋ฐ์ํ
https://www.acmicpc.net/problem/11651
์ฝ๋
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int[][] arr = new int[N][2];
for(int i=0; i<N; i++) {
arr[i][0] = scan.nextInt(); // X์ขํ
arr[i][1] = scan.nextInt(); // Y์ขํ
}
Arrays.sort(arr, new Comparator<int[] >() {
@Override
public int compare(int[] x, int[] y) {
if(x[1] == y[1]) // Y์ขํ๊ฐ ๋์ผํ๋ฉด X์ขํ ์์ผ๋ก ์ ๋ ฌ
return Integer.compare(x[0], y[0]);
return Integer.compare(x[1], y[1]); // Y์ขํ ์์ผ๋ก ์ ๋ ฌ
}
});
for(int i=0; i<N; i++)
System.out.println(arr[i][0] + " " + arr[i][1]);
scan.close();
}
}
ํ์ด
Comparator ์ธํฐํ์ด์ค ์๋ ์ฐธ๊ณ
๋ฐ์ํ
'Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] 2164๋ฒ: ์นด๋2(ํ) (0) | 2020.01.21 |
---|---|
[๋ฐฑ์ค] 13458๋ฒ: ์ํ๊ฐ๋ (0) | 2020.01.21 |
[๋ฐฑ์ค] 10773๋ฒ: ์ ๋ก (0) | 2020.01.20 |
[๋ฐฑ์ค] 2609๋ฒ: ์ต๋๊ณต์ฝ์์ ์ต์๊ณต๋ฐฐ์ (0) | 2020.01.20 |
[๋ฐฑ์ค] 10814๋ฒ: ๋์ด์ ์ ๋ ฌ (0) | 2020.01.20 |
๋๊ธ