| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11595 | DS_2017fall_HW1 |
|
Description
Please check the format of parentheses that is valid or not, and evaluate.
If it is invalid, revise right parentheses or add new right parentheses or delete redundant right parentheses based on the left parentheses, and show the correct format and the evaluate value.
Time Limit: 1 sec
Input
The input is a line of string without any space character and the length of input is between 1 and 1000000.
Each operand is a digit (0 - 9), and the set of operators are: (){}[]+-*/.
Note that the 1st character must be “(“, “{“, or “[“.
There are two kinds of input format:
1. There is some infix expression in the input: e.g. (7/[5+1]
2. There’s no infix expression: e.g. {(})
Input would only contain parentheses, and the value we defined is 0.
Output
There would be 2 cases for the output.
1.If the format of parentheses is valid, output two lines:
First line: True
Second line: the evaluated value
2.If the format of parentheses is invalid, output two lines:
First line: True
Second line: transform the expression to the correct form
Third line: the evaluated value
Both have endl behind value
The output evaluated value (int) will be a Positive or Negative or 0