Send More Money
Input: standard input
Output: standard output
Time Limit: 1 second
|
S |
E |
N |
D |
+ |
M |
O |
R |
E |
______________________ |
||||
M |
O |
N |
E |
Y |
|
9 |
5 |
6 |
7 |
+ |
1 |
0 |
8 |
5 |
______________________ |
||||
1 |
0 |
6 |
5 |
2 |
Problem
constraints
- Each digit
in the original summation was replaced by exactly one uppercase letter.
- There is a one to one relationship between digits and letters.
That means:
- No different digits were replaced by the same
letter.
- No same digits were replaced by different letters.
- The original summation contained no leading zeros in
the numbers (although the value 0 itself was allowed).
You are given the words after the replacement. Can you get the original
summation back?
Input
For each test case, first I’ll give you
Output
Sample Input
2
3
SEND MORE MONEY
3
CROSS ROADS DANGER
Sample Output
D=7 E=5 M=1
N=6 O=0 R=8 S=9 Y=2
A=5 C=9 D=1 E=4 G=7 N=8 O=2 R=6 S=3
Problem setter: Enamul Haque, CSE, CUET.
Thanks to Adrian for alternate solution.
"~~ ZERO +
ZERO + FORTY + FIFTY = NINETY
EINS + EINS + EINS + EINS = VIER
DOS + DOS + TRES = SIETE
CINQ + CINQ + VINGT = TRENTE
TRE + CINQUE + CINQUE = TREDICI
Right? ~~