#C9872. Arithmetic Expression Evaluation

    ID: 54013 Type: Default 1000ms 256MiB

Arithmetic Expression Evaluation

Arithmetic Expression Evaluation

Given a single arithmetic expression consisting of two non-negative integers and an operator, your task is to evaluate the expression. The expression follows the format num1 op num2, where num1 and num2 are non-negative integers, and op is one of the four arithmetic operators: addition (+), subtraction (-), multiplication (*), and integer division (/). For integer division, use the floor division method.

If the input format is incorrect, contains non-numeric values, uses an unsupported operator, or if division by zero is attempted, the output should be Invalid input.

Mathematical formulas used:

  • Addition: \(a + b\)
  • Subtraction: \(a - b\)
  • Multiplication: \(a \times b\)
  • Integer Division: \(a \div b\) (where \(b \neq 0\))

inputFormat

A single line from standard input containing the arithmetic expression in the format: num1 op num2. The elements are separated by spaces.

outputFormat

A single line to standard output that is the result of the arithmetic computation. If the expression is invalid or division by zero occurs, output 'Invalid input'.## sample

12 + 5
17

</p>