Now that you're back to school for another term, you need toremember 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 to39. 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 rst number of the combination turn the dial counter-clockwise 1 full turn continue turning counter-clockwise until the 2nd num-ber is reached turn the dial clockwise again until the 3rd number isreached 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 dialrotated in total (clockwise plus counter-clockwise) in opening the lock?InputInput consists of several test cases. For each case there is a line of input containing 4 numbers between0 and 39. The rst 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 lastcase.OutputFor each case, print a line with a single integer: the number of degrees that the dial must be turned toopen the lock.SampleInput0 30 0 305 35 5 350 20 0 207 27 7 270 10 0 109 19 9 190 0 0 0SampleOutput135013501620162018901890
đang được dịch, vui lòng đợi..
