-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q4p2.java
39 lines (38 loc) · 1.41 KB
/
Q4p2.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
import java.util.*;
import java.io.*;
public class Q4p2{
public static void main(String[] args) {
try{
File file = new File("Q4inp.txt");
Scanner sc = new Scanner(file);
int count = 0;
int e1s, e1e, e2s, e2e;
String line;
while(sc.hasNextLine()){
line = sc.nextLine();
e1s = Integer.parseInt(line.substring(0, line.indexOf('-')));
line = line.substring(line.indexOf('-') + 1);
e1e = Integer.parseInt(line.substring(0, line.indexOf(',')));
line = line.substring(line.indexOf(',') + 1);
e2s = Integer.parseInt(line.substring(0, line.indexOf('-')));
line = line.substring(line.indexOf('-') + 1);
e2e = Integer.parseInt(line);
//find if there is overlap between e1 and e2
if(e1s <= e2s && e1e >= e2s){
count++;
}
else if(e2s <= e1s && e2e >= e1s){
count++;
}else if(e1s <= e2e && e1e >= e2e){
count++;
}else if(e2s <= e1e && e2e >= e1e){
count++;
}
}
System.out.println(count);
sc.close();
} catch (FileNotFoundException e) {
System.out.println("File not found!!");
}
}
}