Rules
()+() = ()() => [combine]
((()))+() = ((())()) => [absorb-right]
()+((())) = (()(())) => [absorb-left]
(())(())+() = (())(()()) => [combined-absorb-right]
()+(())(()) = (()())(()) => [combined-absorb-left]
(())(())+((())) = ((())(())(())) => [absorb-combined-right]
((()))+(())(()) = ((())(())(())) => [absorb-combined-left]
()+(())+((())) = (()())+((())) = ((()())(())) => [left-associative]
For example,
(())+() = ()+(()) = (()())
Input Specification
On the first and only line, one question, . See the sample input for more details. It is guaranteed that will contain at most bracket expressions (thus, at most +
s), and each bracket expression will contain at most characters. Thus, . It is also guaranteed each bracket expression is valid.
Output Specification
Output the answer to the question.
Sample Input 1
()()()+((())())
Sample Output 1
(()()()(())())
Sample Input 2
()()+()()()+(())
Sample Output 2
(()()()()()())
Comments