2220. Puzzle

单点时限: 3.0 sec

内存限制: 256 MB

Background

Some people spend a lot of time solving puzzles of various types. A typical puzzle of the type to be considered here looks like this:

To a given set of equations containing symbols instead of digits, a substitution for each of the symbols by one of the digits 0.....9 must be found so that the equations hold. If you have ever tried a puzzle like this, you know what a tedious task this might be.

The Problem

You are given a set of equations containing the symbols A......J. Find a substitution of the digits 0....9 for these symbols so that all of the given equations hold simultaneously. No two symbols may stand for the same digit. All numbers are positive, and the first digit of each number must not be zero. If several solutions exist, only the lexicographically smallest substitution should be printed.

输入格式

The input consists of multiple scenarios.

Each scenario starts with a line giving the number n of equations, n in the range 1<=n<=10. In each of the following n lines you will find an equation. The syntax looks like that:

line = argument1 [’+’ | ’-’ | ’*’ | ’/’] argument2 ’=’ result

argument1 = digit {digit}*

argument2 = digit {digit}*

result = digit {digit}*

digit = [’A’ | … | ’J’]

Note that not all the symbols ’A’ to ’J’ might appear in the equations. Nevertheless, if one of them appears, then all letters lexicographically smaller than this one appear as well. All numbers involved are guaranteed to have a maximum of 9 digits.

Input is terminated by a line with n = 0.

输出格式

For each scenario print a line containing the following:

  1. the alphabetically ordered list of symbols that appeared in the set of equations

  2. an arrow ’–>’,

  3. the lexicographically smallest substitution of digits for the symbols in the list. If no solution exists, print ’No solution’ instead.

样例

Input
6
EBCE/CED=AE
FBGB-FHBG=ADC
DIAA-GIHJ=FJHF
EBCE-FBGB=DIAA
CED+FHBG=GIHJ
AE*ADC=FJHF
1
A+A=AA
0
Output
ABCDEFGHIJ-->1746823509
A-->No solution

2 人解决,4 人已尝试。

2 份提交通过,共有 7 份提交。

9.1 EMB 奖励。

创建: 16 年,3 月前.

修改: 7 年,2 月前.

最后提交: 3 年,12 月前.

来源: TU Darmstadt Programming Contest 1999

题目标签