#C14044. Evaluate Mathematical Expressions

    ID: 43650 Type: Default 1000ms 256MiB

Evaluate Mathematical Expressions

Evaluate Mathematical Expressions

Given a list of mathematical expressions in string format, your task is to evaluate them sequentially. Each expression is given in the form operand operator operand (for example, 10 + 2), representing a simple arithmetic calculation. If all expressions are valid, output their results separated by spaces.

If any expression is invalid, the program should immediately output an error message and terminate. The error messages are defined as follows:

  • Division by Zero: If an expression involves a division by zero (i.e. in an expression of the form \(\frac{a}{b}\) where \(b=0\)), output: Division by zero in expression: {expression}.
  • Malformed Expression: If an expression does not conform to the required format, output: Malformed expression: {expression}.
  • Non-numeric Evaluation: If the evaluated result is not a number (for example, evaluating 'string'), output: Invalid expression: {expression}. Error: Invalid result type.

All formulas should be formatted in LaTeX if necessary, for example, the division is represented as \(\frac{a}{b}\).

inputFormat

The first line contains an integer \(n\) representing the number of expressions. The next \(n\) lines each contain one arithmetic expression.

outputFormat

If every expression is valid, output the evaluation results separated by spaces.

If any expression is invalid, output the corresponding error message immediately and terminate processing.

## sample
4
10 + 2
5 * 3
8 / 4
7 - 2
12 15 2.0 5