University of Calgary

defective microwave

The Defective Microwave
Source: ACM programming contest
You find a microwave oven for a bargain price at a garage sale, with a note attached to it with the cryptic message:
0 = 6
When you take it home, you discover the meaning of the message: the keypad is broken, and pressing a '0' results in a '6' appearing in the display. However, pressing '6' also results in a '6', and all other keys function properly. After using the microwave a little while you realize that most times can be approximated avoiding the digit '0' in the set time. For example heating a cup of coffee for 59 seconds rather than 60 didn't make a difference. Being a stickler for precision, you decide to write a program to pick out the closest matching times when a zero digit is not available.
 
Here is an example of an input file MICRO2.DAT:
 
3205
220
90
100
9099
1170
1210
3100
 
For the input above, your program will write the following output to the file MICRO2.OUT:
 
Microwave Approximations:
Desired cook time = 3205; Closest approximation(s): 3165
Desired cook time = 220; Closest approximation(s): 179 181 219 221
Desired cook time = 90; Closest approximation(s): 89 91 129 131
Desired cook time = 100; Closest approximation(s): 59 61
Desired cook time = 9099; Closest approximation(s): 9139
Desired cook time = 1170; Closest approximation(s): 1169 1171 1211
Desired cook time = 1210; Closest approximation(s): 1169 1171 1211
Desired cook time = 3100; Closest approximation(s): 3111
 



Updated: August 10, 2005 12:58 PM