
ZOJ Problem Set  2958
To our acknowledgement, numbers can be displayed on computer screen as below, from 0 to 9:
._. ... ._. ._. ... ._. ._. ._. ._. ._. . .. ._ ._ _ _. _. .. _ _ _ .. _. ._ .. ._ _ .. _ ._ As you can see, vertical bars and horizontal bars descript digits. This technology has been used in Cheer bank today. The bank use optical scanner to read the accounts of checks, and display them on computer screen. But there is something wrong with the optical scanner, sometimes it recognizes bars (either vertical or horizontal) as dots. This makes some digit incorrect. To cope with such situation, the bank uses checksum.
The account in a check will always has 9 digit, namely, d_{1}, d_{2}, d_{3}, ..., d_{9}. We consider the account read by the scanner correct if You are to write a program to detect errors and try to correct them. Note: Error seldom occurs. So if this does happen, at most 1 digit would be incorrect. Input There are multiple test cases for this problem. There are three lines for each test. Each line contains 27 characters, with no leading and tailing spaces. And you can assume that there is no malformed input, errors will just replace bars with dots. Output Output the actual account for each test case if there is no error or the error can be corrected. If you can't find any solution, output "failure". If you can find more than one solution, output "ambiguous". Sample Input
...._.._....._.._.._.._.._. ..._.___._...__ ..._.._...__.._._ ._.._.._.._.._.._.._.._.._. _________ _________ ...._.._.._.._.._.._....._. __.._......._. ...____......._ ._....._.._.._.._.._.._.._. _.._______ _.._______ Sample Output
123456789 failure ambiguous 878888888 Hint The solution for the first sample should be 123456789 because the second digit can be 2 or 3, but if it is 3, checksum will not be satisfied. And the fifth digit can be 5 or 6, but if the fifth digit is 6, there will be 2 two incorrect digits, this violates the rule: "at most 1 digit would be incorrect". Author: GAO, Junxin Source: ZOJ Monthly, May 2008 