#C11915. Evaluate Mathematical Expression

    ID: 41284 Type: Default 1000ms 256MiB

Evaluate Mathematical Expression

Evaluate Mathematical Expression

You are given a string representing a mathematical expression. The expression may contain non-negative integers, parentheses, and the operators \(+, -, \times, \div\). Your task is to evaluate the expression and compute its integer result.

The expression should be evaluated using standard operator precedence rules and proper handling of parentheses. Note that the division operator (\(\div\)) should perform integer division (i.e. floor division as in many programming languages) when both operands are integers.

For example:

  • Input: 1 + 1  →  Output: 2
  • Input: (2 + 3) * 4  →  Output: 20
  • Input: 2 + 3 * 4 - 5  →  Output: 9

Read the expression from standard input and print the result to standard output.

inputFormat

Input is provided via standard input. The input consists of a single line containing a valid mathematical expression composed of digits, spaces, parentheses, and the operators +, -, *, and /.

outputFormat

Output the computed integer result of the expression evaluation to standard output. The result should be printed as a single integer on one line.

## sample
1 + 1
2