forked from ajahuang/UVa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UVa 10550 - Combination Lock.cpp
44 lines (40 loc) · 1 KB
/
UVa 10550 - Combination Lock.cpp
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
#include <iostream>
using namespace std;
static const int DEGREE_PER_MARK = 360 / 40;
enum DIRECTION {
CLOCKWISE,
COUNTER_CLOCKWISE
};
int turn(int from, int to, DIRECTION dir)
{
if (dir == CLOCKWISE)
{
if (to >= from)
return (from + (40 - to)) * DEGREE_PER_MARK;
else
return (from - to) * DEGREE_PER_MARK;
}
else
{
if (to >= from)
return (to - from) * DEGREE_PER_MARK;
else
return ((40 - from) + to) * DEGREE_PER_MARK;
}
}
int main()
{
int p1, p2, p3, p4;
while (cin >> p1 >> p2 >> p3 >> p4, p1 + p2 + p3 + p4 > 0)
{
// Turn the dial clockwise 2 full turns.
int totalDegree = 360 * 2;
totalDegree += turn(p1, p2, CLOCKWISE);
// Turn the dial counter-clockwise 1 full turn.
totalDegree += 360;
totalDegree += turn(p2, p3, COUNTER_CLOCKWISE);
totalDegree += turn(p3, p4, CLOCKWISE);
cout << totalDegree << endl;
}
return 0;
}