Notice
Recent Posts
Recent Comments
Link
반응형
변명은 만개 결과는 한개
[백준 11650] 좌표 정렬하기 (java) 본문
728x90
반응형
https://www.acmicpc.net/problem/11650
11650번: 좌표 정렬하기
첫째 줄에 점의 개수 N (1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N개의 줄에는 i번점의 위치 xi와 yi가 주어진다. (-100,000 ≤ xi, yi ≤ 100,000) 좌표는 항상 정수이고, 위치가 같은 두 점은 없다.
www.acmicpc.net
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int N = Integer.parseInt(br.readLine());
int[][] ints = new int[N][2];
for (int i = 0; i < N; i++) {
String[] strs = br.readLine().split(" ");
ints[i][0] = Integer.parseInt(strs[0]);
ints[i][1] = Integer.parseInt(strs[1]);
}
Arrays.sort(ints, (a, b) -> {
if (a[0] == b[0]) {
return a[1] - b[1];
} else {
return a[0] - b[0];
}
});
for (int i = 0; i < N; i++) {
System.out.println(ints[i][0] + " " + ints[i][1]);
}
}
}
728x90
반응형
'공부 > Problem Solving' 카테고리의 다른 글
[백준 23253] 자료구조는 정말 최고야 (java) (0) | 2022.05.03 |
---|---|
[백준 11866] 요세푸스 문제 0 (java) (0) | 2022.05.03 |
[이분 탐색 01] (0) | 2020.07.01 |
[DFS, BFS 01] (0) | 2020.06.26 |
[다이나믹 프로그래밍 01] (0) | 2020.06.25 |