#C12885. Mathematical Expression Evaluation
Mathematical Expression Evaluation
Mathematical Expression Evaluation
You are given a single-line string containing one or more mathematical expressions separated by semicolons (;
). Each expression may include basic arithmetic operations: addition (+), subtraction (-), multiplication (*), and division (/), and can also contain parentheses.
Your task is to evaluate each non-empty expression in the order in which they appear and output the results separated by a single space. Note that if an expression involves division or floating point numbers, the result should be printed with one decimal place (e.g. \(12/4=3.0\)), otherwise, print the integer result.
Details:
- Expressions may include spaces.
- Empty expressions (if any) must be ignored.
- It is guaranteed that all expressions are valid.
Examples:
- Input:
5 + 3; 12 / 4; (7 - 1) * 3;
→ Output:8 3.0 18
- Input:
10 - 7; -4 + 2 * 3; (5 + 2) * -2;
→ Output:3 2 -14
</p>
inputFormat
The input consists of a single line containing a string of mathematical expressions separated by semicolons (;
).
For example:
5 + 3; 12 / 4; (7 - 1) * 3;
outputFormat
Output a single line containing the evaluated results of the expressions in order, separated by a single space. If an expression involves division or a decimal point, the result should be printed with one digit after the decimal point; otherwise, print it as an integer.
## sample5 + 3; 12 / 4; (7 - 1) * 3;
8 3.0 18