Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- class Point implements Comparable<Point>{
- int x, y;
- Point(int x, int y) {
- this.x = x;
- this.y = y;
- }
- @Override
- public int compareTo(Point o) {
- if(this.x < o.x) {
- return -1;
- } else if(this.x == o.x) {
- if(this.y < o.y) {
- return -1;
- } else if(this.y == o.y) {
- return 0;
- } else {
- return 1;
- }
- } else {
- return 1;
- }
- }
- }
- public class Main {
- public static StringBuilder sb = new StringBuilder();
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- Point[] pAry = new Point[n];
- for(int i = 0; i < n; i++) {
- int x = sc.nextInt();
- int y = sc.nextInt();
- pAry[i] = new Point(x,y);
- }
- Arrays.sort(pAry);
- for(Point p : pAry) {
- sb.append(p.x + " " + p.y + "\n");
- }
- System.out.println(sb);
- }
- }
Add Comment
Please, Sign In to add comment