https://www.acmicpc.net/problem/11651
11651번: 좌표 정렬하기 2
첫째 줄에 점의 개수 N (1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N개의 줄에는 i번점의 위치 xi와 yi가 주어진다. (-100,000 ≤ xi, yi ≤ 100,000) 좌표는 항상 정수이고, 위치가 같은 두 점은 없다.
www.acmicpc.net
문제풀이
11650번 좌표정렬하기와 비슷하면 (x좌표랑 y좌표만 바꾸면 된다)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
public class BOJ11651 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine().trim());
int[][] arr = new int[N][2];
String[] str = new String[2];
for (int i = 0; i < N; i++) {
str = br.readLine().split(" ");
arr[i][0] =Integer.parseInt(str[0]);
arr[i][1] = Integer.parseInt(str[1]);
}
Arrays.sort(arr, new Comparator<int[]>() {
@Override
public int compare(int[] x, int[] y) {
if (x[0] == y[0]) {
return Integer.compare(x[1], y[1]);
}
return Integer.compare(x[0], y[0]);
}
});
for (int i = 0; i < N; i++) {
System.out.println(arr[i][0] + " " + arr[i][1]);
}
}
}
'JAVA 알고리즘 ' 카테고리의 다른 글
백준 2661번 - 좋은수열 (0) | 2019.11.02 |
---|---|
백준 6603번 로또 (0) | 2019.11.01 |
백준 11650번 - 좌표정렬하기 (0) | 2019.10.29 |
백준 1026번 - 보물 (1) | 2019.10.29 |
백준 2217번 (0) | 2019.10.23 |