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
-
- Each line of input contains a positive integer in the range 10..9999, left justified in columns 1-4, representing a desired cook time.
- The minutes (if any) and seconds have been concatenated to a single positive integer of the form MMSS, or MSS, or SS.
- In a 4-digit integer, the leftmost 2 digits represent minutes, the rightmost 2 digits represent seconds.
- In a 3-digit integer, the leftmost 1 digit represents minutes, the rightmost 2 digits represent seconds.
- A 2 digit integer represents pure seconds.
- Thus the first input line above represents 32 minutes 5 seconds; the second line represents 2 minutes 20 seconds; the 3rd time represents 90 seconds.
- Each integer in the input will contain at least one zero. The left-most digit will be non-zero.
- 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
-
- For each of the desired cook times in the input, the output will print the desired cook time followed by the closest approximations that do not contain a zero digit.
- Two approximations (to the desired cook time) may actually mean the same length of time: for example 179 and 219.
- Where there are 2 or more closest approximations which approximate the desired cook time equally well, all of them must be listed. In fact they are to be listed so that the integers representing the cook times are in increasing order. For example, 181 is listed before 219 even though 1 minute 81 seconds (= 2 min. 21 sec.) is a longer cook time than 2 minutes 19 seconds.
- Note that 1170 and 1210 represent the same cooktime so yield the same output.
- Observe the labelling and formatting details of the output.
- You may assume that, for each desired cook time, the output will fit in one line having 71 or fewer characters.