All pastes #232518 Raw Edit

Rave Hanker

public text v1 · immutable
·published 2006-11-01 11:34 UTC
rendered paste body
Everyone is aware of problems of the kind

TWO
+ TWO
--------------
= FOUR
--------------

where each of the letters represent a distinct digit from 0-9. Given any input, can you determine all assignment of the values for the letters so that the summation criterion is satisfied? The first letter of either operands or the resultant cannot take value of 0.
Assume that the 2 operands are of the same length. The resultant summation string could either be of same length or one more.
Input :

The input ( given from standard input ) consists of 3 lines. The first line

represents the first operand. The second line represents the second operand and the third line represents the resultant summation. All input letters are specified in uppercase.

The maximum lengths of the operands are 9 and that of the resultant is 10.
Output:

The output is to the standard output . The first line specifies the number of possible solutions(N) for the given input, which is followed by a blank line.

Next, for each of these N possible solutions, 3 lines are printed

•  the first line is the value of the letters of the first operand

•  the second line for the second operand and

•  the third line for the resultant summation.

In each line, no blank spaces separate the digits. Each line is left aligned.

These N possible solutions are ordered in increasing order of the value of the first operand (For eg: If first operand could take values 407 and 402, then solution corresponding to 402 is displayed first and then solution corresponding to 407 is displayed

One blank line separates each of these N solutions.

Sample Input:

TWO
TWO
FOUR

Sample Output
7

734
734
1468

765
765
1530

836
836
1672

846
846
1692

867
867
1734

928
928
1856

938
938
1876