시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 128 MB | 3 | 0 | 0 | 0.000% |
Consider mathematical formulas defined as follows:
a
'-'z
')0
' or '1
'A
'-'Z
')For example 'a
', '0
', 'F(a,F(a,a))
' and 'G(F(0,1),G(a,1))
' are formulas, while 'A
', 'a(9)
' and 'F(G(),a)
' are not.
Formulas that don't contain any variables are called basic formulas.
You are given two formulas. Write a program that will substitute every occurrence (in both formulas) of some variable with some basic formula so that, after substitution, the two formulas become identical.
If a variable appears more than once in one or both formulas then each occurrence has to be substituted with the same basic formula.
Two lines of input contain two formulas. Each will contain at most 100 characters.
The first line of output should contain the substitution for the variable '0
', and the second line should contain the substitution for the variable '1
'.
In both lines the format should be 'variable=basic formula
'. Even if a variable doesn't appear in formulas at all, you should still output a substitution for it.
Note: the test data will be such that a solution, although not necessarily unique, always exists.
0 a
0=a 1=b
F(0,G(a,1)) F(c,G(a,F(0,0)))
0=c 1=F(c,c)
F(G(1,a),G(1,a)) F(0,0)
0=G(b,a) 1=b