Created
May 31, 2022 10:30
-
-
Save mym0404/db3cc7d496621dcd643f6178da27b478 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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