Guest User

Untitled

a guest
Apr 25th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. class Point implements Comparable<Point>{
  5. int x, y;
  6. Point(int x, int y) {
  7. this.x = x;
  8. this.y = y;
  9. }
  10. @Override
  11. public int compareTo(Point o) {
  12. if(this.x < o.x) {
  13. return -1;
  14. } else if(this.x == o.x) {
  15. if(this.y < o.y) {
  16. return -1;
  17. } else if(this.y == o.y) {
  18. return 0;
  19. } else {
  20. return 1;
  21. }
  22. } else {
  23. return 1;
  24. }
  25. }
  26. }
  27.  
  28. public class Main {
  29. public static StringBuilder sb = new StringBuilder();
  30.  
  31. public static void main(String[] args) {
  32. Scanner sc = new Scanner(System.in);
  33. int n = sc.nextInt();
  34. Point[] pAry = new Point[n];
  35. for(int i = 0; i < n; i++) {
  36. int x = sc.nextInt();
  37. int y = sc.nextInt();
  38. pAry[i] = new Point(x,y);
  39. }
  40. Arrays.sort(pAry);
  41. for(Point p : pAry) {
  42. sb.append(p.x + " " + p.y + "\n");
  43. }
  44. System.out.println(sb);
  45. }
  46. }
Add Comment
Please, Sign In to add comment