-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPair.java
More file actions
60 lines (49 loc) · 1.24 KB
/
Copy pathPair.java
File metadata and controls
60 lines (49 loc) · 1.24 KB
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
53
54
55
56
57
58
59
60
import java.io.*;
import java.util.*;
class Pair implements Comparable<Pair> {
public int l;
public int r;
Pair(int l, int r) {
this.l = l;
this.r = r;
}
@Override
public int compareTo(Pair pair) {
if (this.l > pair.l) {
return 1;
} else if (this.l < pair.l) {
return -1;
} else {
if (this.r > pair.r) {
return 1;
} else {
return -1;
}
}
}
}
public class Main {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String line;
int n = Integer.parseInt(br.readLine());
while (n != 0) {
Pair[] blocks = new Pair[n];
// build an array of block pairs
for (int i = 0; i < n; i++) {
String[] tokens = br.readLine().trim().split("\\s+");
int l = Integer.parseInt(tokens[0]);
int r = Integer.parseInt(tokens[1]);
blocks[i] = new Pair(l, r);
}
// using the custom comparator
Arrays.sort(blocks);
// for (Pair p : blocks) {
// System.out.printf("%d %d\n", p.l, p.r);
// }
// System.out.println();
n = Integer.parseInt(br.readLine());
}
}
}