Skip to content

Instantly share code, notes, and snippets.

@dalcon10028
Created December 30, 2019 15:37
Show Gist options
  • Save dalcon10028/4f63cf3c77aa9fa302c46513aca5d21e to your computer and use it in GitHub Desktop.
Save dalcon10028/4f63cf3c77aa9fa302c46513aca5d21e to your computer and use it in GitHub Desktop.
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder(); // 출력이 많으므로 사용합니다.
int N = sc.nextInt();
int [][]pos = new int[N][2];
for(int i=0; i<N; i++){
pos[i][0] = sc.nextInt(); // x 좌표
pos[i][1] = sc.nextInt(); // y 좌표
}
sc.close();
Arrays.sort(pos, new Comparator<int[]>(){
@Override
public int compare(int[] a, int[] b) {
if(a[0] != b[0])
return a[0] - b[0]; // x좌표가 다르면 x 비교
return a[1] - b[1]; // 아니면 y비교
}
});
for (int[] is : pos)
sb.append(is[0] + " " + is[1] + "\n");
System.out.print(sb);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment