티스토리 뷰

[BJ] 11650. 좌표 정렬하기

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.*;
// 210212

public class Main_BJ_11650_좌표정렬하기 {

	static int N;
	static int[][] arr;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		N = sc.nextInt();
		arr = new int[N][2];
		for(int i=0; i<N; i++) {
			arr[i][0] = sc.nextInt();
			arr[i][1] = sc.nextInt();
		}

		Arrays.sort(arr, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				if (o1[0] == o2[0]) {
					return Integer.compare(o1[1], o2[1]);
				}
				
				return Integer.compare(o1[0], o2[0]);
			}
		}  );
		
		StringBuilder sb = new StringBuilder();
		for(int i=0; i<N; i++) {
			sb.append(arr[i][0] + " " + arr[i][1] + "\n");
		}
		System.out.println(sb.toString());
		sc.close();
	}
}

'코딩테스트 > 백준' 카테고리의 다른 글

[BJ] 2606. 바이러스  (0) 2021.02.14
[BJ] 1260. DFS와 BFS  (0) 2021.02.14
[BJ] 1436. 영화감독 숌  (0) 2021.02.14
[BJ] 1018. 체스판 다시 칠하기  (0) 2021.02.14
[BJ] 7568. 덩치  (0) 2021.02.14
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함