Skip to content

Instantly share code, notes, and snippets.

@mym0404
Created May 31, 2022 10:30
Show Gist options
  • Save mym0404/db3cc7d496621dcd643f6178da27b478 to your computer and use it in GitHub Desktop.
Save mym0404/db3cc7d496621dcd643f6178da27b478 to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.Scanner;
class Pair {
int x, y;
Pair(int a, int b) {
this.x = a;
this.y = b;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<Pair> arr = new ArrayList<>();
for(int i = 0; i < n; i++) {
Pair p = new Pair(sc.nextInt(), sc.nextInt());
arr.add(p);
}
arr.sort((a, b) -> {
if(a.y != b.y)
return a.y - b.y;
return a.x - b.x;
});
for(int i = 0; i < n; i++)
System.out.println(arr.get(i).x + " " + arr.get(i).y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment