Archive
UVa Online Judge Challenge "10550"
“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…”

Problem
My Solution
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String temp[] = sc.nextLine().split(" ");
if (Integer.parseInt(temp[0]) == 0 && Integer.parseInt(temp[1]) == 0 && Integer.parseInt(temp[2]) == 0
&& Integer.parseInt(temp[3]) == 0) {
break;
} else {
System.out.println(1080 + ((Integer.parseInt(temp[0]) - Integer.parseInt(temp[1]) + 40) % 40
+ (Integer.parseInt(temp[2]) - Integer.parseInt(temp[1]) + 40) % 40
+ (Integer.parseInt(temp[2]) - Integer.parseInt(temp[3]) + 40) % 40) * 9);
}
}
}
}
Related Reading
Related entries
Selected from shared tags, categories, and nearby entries in the same section.

