DWITE, November 2012, Problem 2
Tommy always gets really bored during his English class. However, Tommy loves Math! He spends most of his free time adding two numbers together (it's actually really exciting!). One day he came up with a brilliant idea to both cure his boredom in English class, and to not get caught by his teacher: add words together! The way Tommy adds two words together is exactly how he would add two numbers:
- Every letter represents a number: , , …,
- Add the words one letter at a time from right to left.
- If the sum of two letters overflows (that is, greater than ), then the letter to write down will be the sum modulo (the remainder) , and the carry will be the quotient you get when you divide the sum by (so essentially same as two numbers in base instead of base ).
For example, (since , and modulo is , which is , and the carry is the quotient you get when you divide by , i.e. , which represents ).
Note that you don't want the answer to have any leading (as that's equivalent to having leading s).
The input will contain 5 test cases. Each case a line with two words, and , separated by a single space. Every word is at least letter and no more than , made up of only uppercase letters.
The output will contain 5 lines of output. Each a single word representing , spelled in uppercase.
Sample Input
CAT DOG
MOM DAD
ABA A
Sample Output
FOZ
POP
BA
Problem Resource: DWITE
Comments