0%

北大 acm 2304 Combination Lock 解题报告

Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2872 Accepted: 1734

Description

Alt text
Now that you’re back to school for another term, you need to remember how to work the combination lock on your locker. A common design is that of the Master Brand, shown at right. The lock has a dial with 40 calibration marks numbered 0 to 39. A combination consists of 3 of these numbers; for example: 15-25-8. To open the lock, the following steps are taken:

turn the dial clockwise 2 full turns
stop at the first number of the combination
turn the dial counter-clockwise 1 full turn
continue turning counter-clockwise until the 2nd number is reached
turn the dial clockwise again until the 3rd number is reached
pull the shank and the lock will open.

Given the initial position of the dial and the combination for the lock, how many degrees is the dial rotated in total (clockwise plus counter-clockwise) in opening the lock?

Input

Input consists of several test cases. For each case there is a line of input containing 4 numbers between 0 and 39. The first number is the position of the dial. The next three numbers are the combination. Consecutive numbers in the combination will be distinct. A line containing 0 0 0 0 follows the last case.

Output

For each case, print a line with a single integer: the number of degrees that the dial must be turned to open the lock.

Sample Input

0 30 0 305 35 5 350 20 0 207 27 7 270 10 0 109 19 9 190 0 0 0

Sample Output

135013501620162018901890

注意:题目是刻度盘在转动而不是指针,还有问的是转盘转过的度数此题理清思路后便不难

代码
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
#include <iostream>

using namespace std;

int main()
{
int h,x,y,z,sum;

while(cin>>h>>x>>y>>z)
{
if(h==0&&x==0&&y==0&&z==0)
break;

sum=0;

sum=360*3;

if(h-x<=0)
sum+=(40+(h-x))*9;
else
sum+=(h-x)*9;

if(x-y>=0)
sum+=(40-(x-y))*9;
else
sum-=(x-y)*9;

if(y-z<=0)
sum+=(40+(y-z))*9;
else
sum+=(y-z)*9;

cout<<sum<<endl;
}

return 0;
}
谢谢您的打赏,我的大英雄 ^_^
Thank you for your generosity, my big hero ^_^

更多内容请关注公众号「西小玛」