-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathboj_11651.java
More file actions
43 lines (31 loc) · 1.11 KB
/
boj_11651.java
File metadata and controls
43 lines (31 loc) · 1.11 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
package sorting;
import java.io.*;
import java.util.Arrays;
public class boj_11651 {
public static void main(String args[]) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int N=Integer.parseInt(br.readLine());
int[][] arr=new int[N][2];
for(int i=0;i<N;i++){
String[] s=br.readLine().split(" ");
arr[i][0]=Integer.parseInt(s[1]);
arr[i][1]=Integer.parseInt(s[0]);
}
//두번째 원소를 기준으로 오름차순 정렬 -> 두번째 원소가 같을 경우 첫번째 원소를 오름차순으로
// Comparator 메소드 사용: https://st-lab.tistory.com/243 해당 블로그 참고
Arrays.sort(arr,(a, b)->{
if(a[0]==b[0]){
return a[1]-b[1];
}
else{
return a[0]-b[0];
}
});
StringBuilder sb=new StringBuilder();
for(int i=0;i<N;i++){
sb.append(arr[i][1]+" "+arr[i][0]).append('\n');
}
System.out.println(sb);
br.close();
}
}