2008/2009 SOUTHERN CALIFORNIA REGIONAL |
|||||||||||||
ACM INTERNATIONAL COLLEGIATE PROGRAMMING CONTEST |
|||||||||||||
|
|||||||||||||
Problem 6 |
|||||||||||||
Painted Calculator |
|||||||||||||
|
|||||||||||||
Patrick has a four function (+, -, ×, ÷) calculator; unfortunately, his sister has decided to be a traditional "evil sibling" and painted over the display. The calculator still functions, but of course you can't see the results. This calculator has a display constructed from seven-segment LEDs, as shown in Figure 1.
This particular calculator only displays three digits of accuracy. There are three seven segment digits, and there are no decimal points since all math is performed using integers (with truncation where appropriate).
If the number on the display happens to be negative, there is a minus sign in front of the number. For a number such as -6, this is done by making the right-most digit a "6" and using the middle segment of the next digit over as the minus sign. For a number such as -123, there is one additional segment to the left of the display. Thus, the number -112 lights up ten segments, made up of nine for the number, and one more for the minus sign. The display thus ranges from "-999" to "999". There's no "plus sign" for positive numbers.
In order to prove that the calculator still operates, and justify scraping off the paint, the back cover is removed and an ammeter is attached to the display. An ammeter measures the current consumed by the device, and each segment of a digit consumes five milliamps per segment. Thus, to display a number such as "798" the current consumption can be predicted as follows:
Digit 7: 3 segments lit = 15 milliamps
Digit 9: 6 segments lit = 30 milliamps
Digit 8: 7 segments lit = 35 milliamps
Total = 80 milliamps
Of course, it's apparent that the number "897" also consumes the same amount of current, as does "789", and for that matter "-891".
The calculator allows you to enter numbers with an optional minus sign and up to three digits, and to either add, subtract, multiply, or divide the numbers. Patrick wishes to prove that the functionality of the calculator is intact, so he enters "949" and measures 80 milliamps. Then he pushes the subtract key. Next he enters "51" and measures 35 milliamps. After pressing the "=" key the result should be "898", measuring 100 milliamps. As a second example, he enters "-5", then pushes the addition key. He then enters "-4" and presses equal. The answer is "-9"; the measurements were 30 milliamps, 25 milliamps, and 35 milliamps respectively.
Patrick's sister claims that this is a trick, so she presents him with the following problem: given the current consumption (milliamps) of operand X, operand Y, and result Z, and given unknown operation Op, determine the number of possible solutions for X Op Y = Z, if any.
Note that in all cases there are only three digits on the display. Although the input values of 80, 35, and 100 potentially could represent 949 × 13 = 12337, this is not possible because 12337 is too large for the three digit display to hold.
For example, for input values of 25, 25, 20 there are five possible results: -11 - -4 = -7, -4 - 3 = -7, 2 + 2 = 4, 2 × 2 = 4, and 71 ÷ 17 = 4. Some input combinations have no result-for the values 35, 10, 10 there is no possible answer. Note that no leading zeroes should be considered-the number "23" is never entered or displayed on the calculator as "023" even though the result of the calculation may be the same. Thus, no value should contain numbers with leading zeroes.
Input to your program will be a series of test cases, one per 80-column line. Each input line for the program contains positive integer values for X, Y, and Z, separated from each other by one or more spaces. Each number represents the number of milliamps used by an entered value as described above. Input ends with the end-of-file.
For each test case, your program is to determine the number of possible solutions and print the count on a line beginning in the first column. No trailing whitespace is to appear after the result.
|
|
Sample Input |
25 25 20
35 10 10
15 20 30
30 65 65
Output for the Sample Input |
5
0
9
819
Seven-segment display |
The digits |
|
|
Figure 1. Seven-segment display
File translated from TEX
by TTH,
version 3.77.
On 18 Nov 2008, 22:51.