g*****u 发帖数: 298 | 1 Given an expression remove the unnecessary brackets in it with out creating
an ambiguity in its execution.
input output
ex1: (a+(b)+c) a+b+c
ex2: (a*b)+c a*b+c | b***e 发帖数: 1419 | 2 This is a simple parsing/pretty printing problem. First parse the given
string to an abstract syntax tree, then recurse the tree structure and
apply a straightforward pretty printing algorithm: for each internal node
(representing a binary operator), if its precedence is lower than the
precedence of its parent node, then print surrounding parenthesis. | n******h 发帖数: 50 | 3 if there are only addition and multiplication, it seems to me the only cases
where we need to keep the brackets are:
*(..+..+..) and (..+..+..)* |
|