One Extra Digit
This problem was part of the CCSCSE 2014 problem set. (It was problem 4, and is used here without permission based on the forgiveness model.)
Bob is a great bookkeeper. But there is one mistake he occasionally makes. While adding up a long list of numbers, he sometimes types and extra stray digit in a two-digit number maing it an erroneous three-digit number. For example, the number 82 might be mistyped as 862 due to the extra stray digit 6. As a result, his sums are noticeably a little too high. In the case of typing 862 instead of 82, his sum would be off by the difference, i.e. 862-82 = 780.
Let's write a program to help Bob find his error. That is to say, if Bob knows by how much his sum is off, there should be some way of figuring out which three digit number(s) could potentially be the two digit number that has an extra digit. let's assume that when Bob computes a sum, he only makes this error once.
- A two-digit number is an integer where
- A three-digit number is an integer where .
An instance of this problem will be a number , representing the difference between the correct and incorrect sum. This number will be a positive integer, and will equal , where is a two-digit number and is a three-digit number, and can be obtained from by the appending of an additional digit(0-9) either at the beginning, middle, or end of . For example, the digit 6 could be appended into the number 82 to produce the three possible numbers 682, 862, and 826 depending on whether the 6 is put at the beginning, middle, or end.
An example instance of this problem is where . Then a possible value for is 826 and its corresponding value of would be 82. In this case the 6 was concatenated to the end of to produce . Note that many possible values of could exist for a particular value of . In other words, each problem instance could have several solutions. It's also possible to have no solution.
Your program should be written so that it can process several instances (i.e. test cases) of this problem. The first line of the input will give you , the number of test cases. Assume that . Each of the next lines of the input will give a value for . In your output, you need to identify the test case number, and all solutions of that test case. Print each solution to a test case on its own line. A solution will be specified in the form . print one space on either side of the minus sign, and one space on either side of the equals sign. Also format your solutions so that they are indented by two spaces. See the example I/O below.
If there is more than one solution to a test case, then your solutions must be sorted in ascending order of . Within a test case, do not print the same solution more than once. If a test case has no solution, then you should print "No solution for d= <value of d>" where the value of appears after the equals sign. As with a bona fide solution, this statement should also be indented two spaces.
4 682 390 81 207
Test case 1 757 - 75 = 682 Test case 2 430 - 40 = 390 431 - 41 = 390 432 - 42 = 390 433 - 43 = 390 434 - 44 = 390 435 - 45 = 390 436 - 46 = 390 437 - 47 = 390 438 - 48 = 390 439 - 49 = 390 Test case 3 No solution for d = 81 Test case 4 229 - 22 = 207 230 - 23 = 207
Programming team, post your solutions to the following page: progTeam:One_Extra_Digit_Solutions