#C12358. Evaluate Arithmetic Expression

    ID: 41776 Type: Default 1000ms 256MiB

Evaluate Arithmetic Expression

Evaluate Arithmetic Expression

You are given a string representing a mathematical expression containing non-negative integers, operators +, -, *, /, and parentheses. The expression may include spaces. Your task is to compute the result of the expression using integer arithmetic (i.e. integer division is applied for the division operator). For example, the expression 3+(2*2) evaluates to 7.

The evaluation follows the standard operator precedence rules:

  • Addition and subtraction: $+$ and $-$, with precedence 1.
  • Multiplication and division: $\times$ and $\div$, with precedence 2.
Parentheses can be used to override these precedences.

inputFormat

The input is provided as a single line from stdin which contains the string expression to be evaluated. The expression may contain spaces.

Format: a single line string.

outputFormat

Output the evaluated integer result to stdout.

Format: a single integer.

## sample
3+(2*2)
7