Combination Lock |
Time Limit: 1 Seconds Memory Limit: 65535 K Total Submit:72 Accepted:46 |
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: 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 |
#include<iostream.h> int main() { int a1,a2,a3,a4,sum; while(cin>>a1>>a2>>a3>>a4&&(a1||a2||a3||a4)) { if(a1-a2<0) sum=a1-a2+40; else sum=a1-a2; if(a3-a2<0) sum=sum+a3-a2+40; else sum=sum+a3-a2; if(a3-a4<0) sum=sum+a3-a4+40; else sum=sum+a3-a4; cout<<sum*9+1080<<endl; } return 0; }