fjnu 1501 Combination Lock

 

Description

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 30
5 35 5 35
0 20 0 20
7 27 7 27
0 10 0 10
9 19 9 19
0 0 0 0

Sample Output

1350
1350
1620
1620
1890
1890
KEY:这题我一直感觉很BT,居然是表盘在转…所以想的顺时针逆时针都错了……

  
  
Source:

#include
< iostream >
using   namespace  std;

int  count( int  a, int  b, int  c, int  d)
{
    
int sum=0;
    
if(a>b)
    
{
        sum
+=(a-b)*9;
    }

    
else sum+=(40-(b-a))*9;
    
if(b>c)
    
{
        sum
+=(40-(b-c))*9;
    }

    
else sum+=(c-b)*9;
    
if(c>d)
    
{
        sum
+=(c-d)*9;
    }

    
else sum+=(40-(d-c))*9;
    
return sum;

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值