#C14465. Evaluate Algebraic Expression

    ID: 44117 Type: Default 1000ms 256MiB

Evaluate Algebraic Expression

Evaluate Algebraic Expression

You are given an algebraic expression in the form of a string. The expression contains non-negative integers, binary operators +, -, *, /, and parentheses ( and ). The operator / represents integer division.

Your task is to parse the expression and evaluate its result. The expression follows the conventional operator precedence:

  • Parentheses: \( ( \) are evaluated first.
  • Multiplication and Division: \( * \) and \( / \) come next.
  • Addition and Subtraction: \( + \) and \( - \) are evaluated last.

Note: All operations are left-associative. You can assume the input expression is valid.

inputFormat

The input consists of a single line containing an algebraic expression. The tokens (numbers, operators, and parentheses) are separated by one or more spaces.

For example:

3 + 5

outputFormat

Output a single integer which is the result of evaluating the algebraic expression.

## sample
3 + 5
8