-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFencePainting.java
More file actions
25 lines (22 loc) · 839 Bytes
/
Copy pathFencePainting.java
File metadata and controls
25 lines (22 loc) · 839 Bytes
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
import java.util.Scanner;
public class FencePainting{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int jStart = sc.nextInt();
int jEnd = sc.nextInt();
int bStart = sc.nextInt();
int bEnd = sc.nextInt();
if(bStart>jStart && bStart<jEnd || bEnd>jStart && bEnd<jEnd || jStart>bStart && jStart<bEnd || jEnd>bStart && jEnd<bEnd){
if(bStart>jStart && bEnd<jEnd){
System.out.print(jEnd-jStart);
} else if(jStart>bStart && jEnd<bEnd) {
System.out.println(bEnd-bStart);
} else{
System.out.println(Math.max(jEnd, bEnd) - Math.min(jStart, bStart));
}
} else{
System.out.println((bEnd-bStart) + (jEnd-jStart));
}
sc.close();
}
}