PROGRAMMING:Expression evaluation
Write a program, input a legal expression from the keyboard, evaluate and output the expression. In order to reduce the difficulty of the topic, the following requirements are made:
*All operands are integer numbers (i.e. without decimal point)
*Operators only support four kinds of addition, subtraction, multiplication and division ('+, -, *, /') and parentheses ('()')
*The calculation rule is a real number operation rule, for example, ` 1 / 2 = 0.5`
*Output calculation results to two decimal places (rounded)
*The following is not allowed in an expression
1. Empty string
2. Wrong operator
3. Wrong number of operands
4. The brackets do not match
5. Empty brackets
6. Continuous operators, such as' - 5`
7. When the operator is a positive number, the symbol '+' must be omitted, for example '+ 2 + 4' is defined as illegal, while when the operator is a negative number, it is legal, for example '- 2 + 4'`
8. The program should be able to handle the space in the middle of the expression (the space in the input expression is legal)
9. Other situations that do not conform to the expression writing rules
###Input format:
Enter a line of expression from the keyboard. For example, ` 2 + 3 * (5 - 6 / 4) / 3 + 26-300 * 3 / 29`
###Output format:
There are three outputs:
*When the expression is illegal, output ` wrong format`
*In the case that cannot be calculated (e.g. divide by 0), the output ` input expression = Nan`
*When it can operate correctly, the output 'input expression = calculation result`
###Input sample 1:
Here is a set of inputs. For example:
```in
2+3*(5 -6 / 4)/3 +26-300*3/29
```
###Output sample 1:
The corresponding output is given here. For example:
```out
2+3*(5 -6 / 4)/3 +26-300*3/29 = 0.47
```
###Input sample 2:
Here is a set of inputs. For example:
```in
2+3- 5 / 0
```
###Output sample 2:
The corresponding output is given here. For example:
```out
2+3- 5 / 0 = NaN
```
###Input sample 3:
Here is a set of inputs. For example:
```in
((2-3/4*5/4 +8-0.4)/100-003*5
```
###Output sample 3:
The corresponding output is given here. For example:
```out
Wrong Format
```
answer:If there is no answer, please comment
*Use two stacks, one operator stack and one operand stack
*Test can use Baidu, in the baidu input box directly enter the correct expression to be tested, you can calculate the correct value (note that this topic only retains two decimal places)
*There are a lot of code about this topic on the network, for reference, do not plagiarize, this operation will carry out the whole network detection
*All operands are integer numbers (i.e. without decimal point)
*Operators only support four kinds of addition, subtraction, multiplication and division ('+, -, *, /') and parentheses ('()')
*The calculation rule is a real number operation rule, for example, ` 1 / 2 = 0.5`
*Output calculation results to two decimal places (rounded)
*The following is not allowed in an expression
1. Empty string
2. Wrong operator
3. Wrong number of operands
4. The brackets do not match
5. Empty brackets
6. Continuous operators, such as' - 5`
7. When the operator is a positive number, the symbol '+' must be omitted, for example '+ 2 + 4' is defined as illegal, while when the operator is a negative number, it is legal, for example '- 2 + 4'`
8. The program should be able to handle the space in the middle of the expression (the space in the input expression is legal)
9. Other situations that do not conform to the expression writing rules
###Input format:
Enter a line of expression from the keyboard. For example, ` 2 + 3 * (5 - 6 / 4) / 3 + 26-300 * 3 / 29`
###Output format:
There are three outputs:
*When the expression is illegal, output ` wrong format`
*In the case that cannot be calculated (e.g. divide by 0), the output ` input expression = Nan`
*When it can operate correctly, the output 'input expression = calculation result`
###Input sample 1:
Here is a set of inputs. For example:
```in
2+3*(5 -6 / 4)/3 +26-300*3/29
```
###Output sample 1:
The corresponding output is given here. For example:
```out
2+3*(5 -6 / 4)/3 +26-300*3/29 = 0.47
```
###Input sample 2:
Here is a set of inputs. For example:
```in
2+3- 5 / 0
```
###Output sample 2:
The corresponding output is given here. For example:
```out
2+3- 5 / 0 = NaN
```
###Input sample 3:
Here is a set of inputs. For example:
```in
((2-3/4*5/4 +8-0.4)/100-003*5
```
###Output sample 3:
The corresponding output is given here. For example:
```out
Wrong Format
```
answer:If there is no answer, please comment
*Use two stacks, one operator stack and one operand stack
*Test can use Baidu, in the baidu input box directly enter the correct expression to be tested, you can calculate the correct value (note that this topic only retains two decimal places)
*There are a lot of code about this topic on the network, for reference, do not plagiarize, this operation will carry out the whole network detection