-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuva-10550.cpp
More file actions
56 lines (45 loc) · 1.28 KB
/
uva-10550.cpp
File metadata and controls
56 lines (45 loc) · 1.28 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
int main()
{
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
int initPos, currentPos, a, b, c, d, total;
while (scanf("%d%d%d%d", &initPos, &a, &b, &c), (initPos || a || b || c)) {
/// clockwise 2 full turns
total = 80;
currentPos = initPos;
/// stop at 1st number of combination in clockwise turn
if (currentPos >= a) {
d = currentPos - a;
}
else {
d = 40 - (a - currentPos);
}
total += d;
currentPos = a;
/// counter-clockwise 1 full turn
total += 40;
/// continue turning counter-clockwise until the 2nd number is reached
if (currentPos <= b) {
d = b - currentPos;
}
else {
d = (40 - currentPos) + b;
}
total += d;
currentPos = b;
/// turn the dial clockwise again until the 3rd number is reached
if (currentPos >= c) {
d = currentPos - c;
}
else {
d = 40 - (c - currentPos);
}
total += d;
currentPos = c;
total *= 9;
printf("%d\n", total);
}
return 0;
}