当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3773:Parenthesis

题目描述
To a computer, there is no difference between the expression (((x)+(y))(t)) and (x+y)t; but, to a human, the latter is easier to read. When writing automatically generated expressions that a human may have to read, it is useful to minimize the number of parentheses in an expression. We assume expressions consist of only two operations:
addition (+) and multiplication (juxtaposition), and these operations act on single lower-case letter variables only. Specifically, here is the grammar for an expression E:
E : P | P '+' E
P : F | F P
F : V | '(' E ')'
V : 'a' | 'b' | .. | 'z'
The addition (+, as in x+y) and multiplication (juxtaposition, as in xy) operators are associative: x+(y+z)=(x+y)+z=x+y+z and x(yz)=(xy)z=xyz. Commutativity and distributivity of these operations should not be assumed. Parentheses have the highest precedence, followed by multiplication and then addition.
输入解释
The input consists of a number of cases. Each case is given by one line that satisfies the grammar above. Each expression is at most 1000 characters long.
输出解释
For each case, print on one line the same expression with all unnecessary parentheses removed.
输入样例
x
(x+(y+z))
(x+(yz))
(x+y(x+t))
x+y+xt
输出样例
x
x+y+z
x+yz
x+y(x+t)
x+y+xt
来自杭电HDUOJ的附加信息
Recommend notonlysuccess

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-3773

最后修改于 2020-10-25T23:06:53+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 32768/32768K(Java/Others)