-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcombinationlock.java
30 lines (28 loc) · 1.23 KB
/
combinationlock.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
import java.io.*;
import java.util.*;
public class combinationlock {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int tick = 360 / 40;
while(true) {
int degrees = 720;
String line = in.readLine();
if(line.equals("0 0 0 0")) break;
String[] input = line.split(" ");
int start = Integer.parseInt(input[0]);
int first = Integer.parseInt(input[1]);
int second = Integer.parseInt(input[2]);
int third = Integer.parseInt(input[3]);
if(first > start) degrees += tick * ((40 - first) + start);
else degrees += tick * Math.abs(start - first);
degrees += 360;
if(second < first) degrees += tick * ((40 - first) + second);
else degrees += tick * Math.abs(second - first);
if(third > second) degrees += tick * ((40 - third) + second);
else degrees += tick * Math.abs(third - second);
out.println(degrees);
}
out.close();
}
}