Problem Description Write a program to solve a set of magic formula.

A magic formula is obtained by transforming an ordinary formula like 120 + 456 = 576 into ZAD + REC = EFC. The transformation is done by setting 1 to Z, 2 to A, 0 to D, 4 to R, 5 to E, 6 to C, and 7 to F.

Now given a set of magic formula, find the digits represented by the letters appearing in the formula. Note that there will be at most 10 different upper case letters in these formula, the leading letter of all numbers could not be 0, and different letters represent different digits.

For example, the Z, R, and E could not be 0 in ZAD + REC = EFI, and all Z, A, D, R, E, C, F, and I represent different digits. It is also guaranteed that there will be exactly one set of solution. The magic could be addition (+), subtraction (-), or multiplication (*). The number of magic formula is no more than 3, the number of digits of every number is no more than 5, and all numbers are positive.

Input Format The first line contains a integer N, which is the number of magic formula (ranged from 1 to 3, both inclusive) And each of the following N lines contains a magic formula. The format of magic formula is

lvalue op rvalue = result

where lvalue, rvalue, and result are strings with upper case letters, and op is the operator (either +, -, or * ). Note that they are seperated by exactly one space.

Output Format For each magic formula, your program should output the ordinary formula. Each formula a line with the same order of original formula, and seperate each number and operator by exactly one space. Example

Sample Input:

1 SEND + MORE = MONEY

Sample Output:

9567 + 1085 = 10652 Sample Input:

3 MADE + MEAD = EDAM EME * EME = CCDCC HK - GF = FC

Sample Output:

1692 + 1269 = 2961 212 * 212 = 44944 87 - 53 = 34

Ads

View Answers

Related Tutorials/Questions & Answers:

Ads

- Java Tutorials
- Java Code example
- Java Programming
- Java Beginners Examples
- Applet Tutorials
- Awt Tutorials
- Java Certification
- Interview Question
- Java Servlets Tutorial
- Jsp Tutorials
- Java Swing Tutorials
- JDBC Tutorial
- EJB Tutorials
- Java Server Faces (JSF) Tutorial
- WAP Tutorial
- Struts Tutorial
- JAXB Tutorial
- Spring FrameWork Tutorial
- SOA&Web Services Tutorials
- Bioinformatics Tutorials
- MySQL Tutorials
- JAVA DOM Tutorial
- XML Tutorial
- EAI Articles
- Many Programming Tutorials Links
- Tutorials Books
**Java Script Tutorial****Ajax Tutorial****Dojo Tutorials****Programming Books****Trainings****Flex****Ant****RDF**