Combination Lock

2020年1月17日 1686点热度 0人点赞 0条评论

Combination Lock

时间: 1ms        内存:128M

描述:

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 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.

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

输入:

输出:

示例输入:

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

示例输出:

1350
1350
1620
1620
1890
1890

提示:

参考答案:

解锁文章

没有看到答案?微信扫描二维码可免费解锁文章

微信扫描二维码解锁

使用微信扫描二维码打开广告页面后可以立即关闭,再刷新此页面即可正常浏览此文章

所跳转广告均由第三方提供,并不代表本站观点!

已经扫描此二维码?点此立即跳转

code

这个人很懒,什么都没留下

文章评论