#C14554. Arithmetic Operations Evaluator

    ID: 44216 Type: Default 1000ms 256MiB

Arithmetic Operations Evaluator

Arithmetic Operations Evaluator

You are given a list of strings, where each string represents a simple arithmetic operation in the form operand operator operand. The operator can be one of the following: addition (+), subtraction (-), multiplication (*), division (/), or exponentiation (**). Your task is to evaluate each operation and output its result.

If the operation is valid, output the numerical result. For division, if the divisor is zero, output the error message:
\(\text{Error: Division by zero}\). For any operation that cannot be correctly parsed or executed, output:
\(\text{Error: Invalid operation}\).

Note:

  • For division operations, always output the result in a floating-point format (e.g. 4.0 instead of 4).
  • You must read the input from standard input (stdin) and write the result to standard output (stdout).
  • The operation should exactly consist of three tokens separated by spaces: the first operand, an operator, and the second operand.

inputFormat

The first line contains an integer \(n\), representing the number of operations. This is followed by \(n\) lines, each line containing an arithmetic operation in the format:

operand operator operand

Examples of valid operations: "3 + 5", "10 - 2", "6 * 4", "8 / 2", "5 ** 2".

outputFormat

For each operation, output its result on a new line. If the operation is valid, print the numerical result. In the case of a division, print the result in a floating-point format with one digit after the decimal point. If an error occurs, output the corresponding error message:

  • Error: Division by zero
  • Error: Invalid operation
## sample
4
3 + 5
10 - 2
6 * 4
8 / 2
8

8 24 4.0

</p>