1999 Canadian Computing Competition, Stage 1
Problem 5: Letter Arithmetic
A popular form of pencil game is to use letters to represent digits in a mathematical statement. An example is
SEND +MORE ----- MONEY
9567 +1085 ----- 10652
Your task is to read in sets of three “words” and assign unique digits to the letters in such a way as to make the sum of the first two words equal to the third word.
The input begins with a line containing a positive integer n which is the number of test data sets. Each data set consists of three lines, each of which contains one word with the third word being the sum of the first two. The words will contain no more than 20 upper case letters.
The output is to consist of n sets of lines each containing the numeric representation of each word in the corresponding test data set. There will be exactly one correct solution for each data set. Leave an empty line after the output for each data set.
2 SEND MORE MONEY MEND COPE CONEY
9567 1085 10652 9567 1085 10652
Point Value: 15
Time Limit: 2.00s
Memory Limit: 16M
Added: Sep 29, 2008
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3