-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day67.java
52 lines (46 loc) · 1.21 KB
/
Day67.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Class with Comparators
// https://www.interviewbit.com/problems/class-with-comparators/
import java.lang.*;
import java.util.*;
public class Day67 {
public static void main(String[] args) {
/****Don't alter the code below*****/
Scanner in = new Scanner(System.in);
ArrayList<pair> arr = new ArrayList<pair>();
int n = in.nextInt();
in.nextLine();
for(int i = 0;i<n;i++)
{
int a = in.nextInt();
int b = in.nextInt();
arr.add(new pair(a,b));
in.nextLine();
}
in.close();
Collections.sort(arr);
for(int i=0;i<n;i++)
{
System.out.println(arr.get(i).first + " " + arr.get(i).second);
}
/*********************************************************************/
}
}
//your code goes here
class pair implements Comparable<pair>
{
int first;
int second;
public pair(int a,int b)
{
this.first = a;
this.second = b;
}
@Override
public int compareTo(pair b)
{
if(this.second == b.second)
return b.first - this.first;
else
return b.second - this.second;
}
}