#C14071. Evaluate Mathematical Expressions

    ID: 43680 Type: Default 1000ms 256MiB

Evaluate Mathematical Expressions

Evaluate Mathematical Expressions

You are given a number of mathematical expressions in string format. Your task is to evaluate each expression and output the result. The expressions can contain addition (+), subtraction (-), multiplication (*), division (/), parentheses, and may include negative numbers. The operations follow the conventional operator precedence (parentheses first, then multiplication and division, and finally addition and subtraction). For example, the expression (7-2)*3+1 is evaluated as follows:

$$ (7-2)*3+1 = 5 \times 3 + 1 = 15 + 1 = 16 $$

Input will be provided via standard input. The first line contains an integer \(n\) representing the number of expressions. The following \(n\) lines each contain one expression. For each expression, output its evaluated result on a separate line. Note that division results should be output as floating point numbers (e.g., 12/4 should be output as 3.0).

inputFormat

The first line contains a single integer \(n\) (\(1 \le n \le 100\)), which is the number of expressions. The next \(n\) lines each contain a valid mathematical expression containing numbers and operators (+, -, *, /) and parentheses.

Example:

4
3+5
12/4
7-2*3+1
(7-2)*3+1

outputFormat

Output \(n\) lines to standard output, where each line corresponds to the evaluated result of the corresponding input expression.

Example:

8
3.0
2
16
## sample
4
3+5
12/4
7-2*3+1
(7-2)*3+1
8

3.0 2 16

</p>