#C8311. Evaluate Multiple Mathematical Expressions
Evaluate Multiple Mathematical Expressions
Evaluate Multiple Mathematical Expressions
You are given a list of mathematical expressions, each in string format. Your task is to evaluate each expression and output its result in the same order. Each expression may contain the following operators:
- Addition: \( + \)
- Subtraction: \( - \)
- Multiplication: \( * \)
- Division: \( / \) (which yields a floating-point result if necessary)
The operations must be evaluated following standard arithmetic rules and operator precedence. If the resulting value is a whole number (e.g., 5.0), print it without any decimal point.
You may assume that all expressions are valid and contain no invalid characters.
inputFormat
The first line of the input contains an integer (T), the number of expressions. Each of the next (T) lines contains one mathematical expression in string format.
outputFormat
For each expression, print the evaluated result in a separate line. If the result is a whole number, output it as an integer; otherwise output the floating-point result.## sample
4
2+3
10/2
6*4-2
8+2*5
5
5.0
22
18
</p>