问题1641--BUILD GATES

1641: BUILD GATES

[命题人 : ]
时间限制 : 1.000 sec  内存限制 : 64 MB

题目描述

Make do without an OR gate Your cousin Bill has a patented process that produces AND and NOT circuits very efficiently. Unfortunately, OR logic is very expensive. He offers to wash your laundry for the next year if you can fix the problem.

输入

A sequence of logical expressions, one per line, which conform to the following grammar: E := '!' E | '(' E '&' E ')' | '(' E '|' E ')' | V V := 'a' | 'b' | ... | 'z' Here the bold are nonterminals or parts of the BNF grammar, while the 'teletype' are terminals. Of course '!' is unary NOT, '&' is binary AND, and '|' is binary OR. Other than end-of-line terminators marking the end of each expression, there will be no white space in the input file.

输出

For each expression in the input, you are to produce an equivalent expression in the output, i.e., one that gives the same truth value for all possible combinations of the input, but without using the '|' OR operation. The generated expression must conform to the same grammar, with the same white space restrictions.

样例输入 Copy

x
(x&!(y|!z))
!(x|y)

样例输出 Copy

Program 3 by team 0
x
(x&(!y&z))
(!x&!y)
End of program 3 by team 0