-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSleepyCowHerding.java
More file actions
42 lines (39 loc) · 1.26 KB
/
Copy pathSleepyCowHerding.java
File metadata and controls
42 lines (39 loc) · 1.26 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
import java.util.Scanner;
import java.util.Arrays;
public class SleepyCowHerding {
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
int[] positions = new int[3];
positions[0] = sc.nextInt();
positions[1] = sc.nextInt();
positions[2] = sc.nextInt();
Arrays.sort(positions);
int min=0;
int max=0;
//comment
if(positions[2]-positions[1] == 2 || positions[1]- positions[0] == 2){
min = 1;
}
else if(positions[2]-positions[1] == 1 && positions[1]-positions[0] == 1){
min = 0;
}else{
min = 2;
}
if(positions[2]-positions[1]<=positions[1]-positions[0]){
while(positions[2]-positions[1] != 1 || positions[1]-positions[0] !=1){
positions[2] = positions[1];
positions[1] = positions[1]-1;
max++;
}
} else{
while(positions[2]-positions[1] != 1 || positions[1]-positions[0] !=1){
positions[0] = positions[1];
positions[1] = positions[1]+1;
max++;
}
}
System.out.println(min);
System.out.println(max);
sc.close();
}
}