Created
July 24, 2018 13:05
-
-
Save mingyu-lee/3ae746f963ae31a41f13ff15affdedf6 to your computer and use it in GitHub Desktop.
BOJ_11650_OrderCoordinate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package boj; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Arrays; | |
public class OrderCoordinate { | |
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
int numberOfInput = Integer.parseInt(br.readLine().trim()); | |
int[][] coordinate = new int [numberOfInput][2]; | |
for (int i = 0; i < numberOfInput; i++) { | |
String[] str = br.readLine().split(" "); | |
coordinate[i][0] = Integer.parseInt(str[0]); | |
coordinate[i][1] = Integer.parseInt(str[1]); | |
} | |
Arrays.sort(coordinate, (x, 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 < numberOfInput; i++) { | |
System.out.println(coordinate[i][0] + " " + coordinate[i][1]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
문제 풀이 소감 :
처음에는 좌표를 어떻게 구현할까 생각했었는데 간단히 2차원 배열로 할 수 있는 것을 쉽게 생각하지 못했다.
아무래도 CRUD 서비스 구현에 집중한 웹 개발만 하다보니 좀더 자료구조를 활용하는 기본기가 몸에 베이지 않은 것 같다.
체감 난이도 :
보통
어려웠던 점 :
정렬 기준이 한 개가 아니었는데, 이를 구현을 어떻게 해야 하나 싶었다. Arrays.sort를 활용하면서 인라인 펑션을 쓰는 것을 쉽게 생각치 못했었다.
앞으로 필요할 것 같은 공부 :
Arrays.sort, 정렬 알고리즘