-->
当前位置:首页 > 题库

PROGRAMMING:Expression evaluation

Luz5年前 (2021-05-10)题库409
After mastering the operation of addition and subtraction, robot card has recently learned some simple function evaluation. For example, it knows that the value of min (20,23) is 20, the value of add (10,98) is 108, and so on. After training, the robot card can even calculate a nested more complex expression.
Suppose that the expression can be simply defined as:
1、 A positive decimal number x is an expression.
2、 If x and y are expressions, then the function min (x, y) is also an expression, and its value is the smallest of X, y.
3、 If x and y are expressions, then the function max (x, y) is also an expression, and its value is the largest number in X, y.
4、 If x and y are expressions, then the function add (x, y) is also an expression, and its value is the sum of X and y.
5、 If x and y are expressions, then the function sub (x, y) is also an expression whose value is the difference between X and y.
For example, the expression max (add (1,2), 7) has a value of 7.
Please write a program to help Dr. Kong calculate the correct answer for a given set of expressions, so as to check the correctness of cardo's calculation.
###Input format:
The first line: n represents the number of expressions to be calculated (1 ≤ n ≤ 10)
Next there are n lines, each of which is a string representing the expression to be evaluated.
(there will be no extra spaces in the expression, no more than 300 characters per line, and no more than 1000 decimal numbers in the expression).
###Output format:
The output has n lines, and each line corresponds to the value of an expression.
###Input example:
Here is a set of inputs. For example:
```in
three
add(1,2)
sub(1,999)
add(min(1,1000),add(100,99))
```
###Output example:
The corresponding output is given here. For example:
```out
three
-998
two hundred
```







answer:If there is no answer, please comment