#C13524. Evaluate Mathematical Expressions
Evaluate Mathematical Expressions
Evaluate Mathematical Expressions
You are given N mathematical expressions. Each expression is a valid arithmetic expression that may include integers, the operators +
, -
, *
, /
, and parentheses.
Your task is to evaluate each expression and print the result as a floating point number. Note that the expressions can have nested parentheses and should follow the usual order of operations. The result for each expression should be computed using the standard arithmetic rules.
The arithmetic expression grammar can be defined as follows (in LaTeX format):
$$\text{Expression} \to \text{Term} \; (('+'|'-') \; \text{Term})^* \\ \text{Term} \to \text{Factor} \; (('*'|'/') \; \text{Factor})^* \\ \text{Factor} \to \text{Number} \; \text{ or } \; '(' \; \text{Expression} \; ')' $$inputFormat
The first line contains an integer N
, representing the number of expressions.
This is followed by N
lines, each containing one arithmetic expression as a string.
You need to read the input from stdin.
outputFormat
Output N
lines, each line containing the evaluated result of the corresponding expression in the input.
The results should be printed as floating point numbers and written to stdout.
## sample3
3+5
(2+3)*4
10/(2+3)
8.0
20.0
2.0
</p>