#C14499. Evaluate Mathematical Expression
Evaluate Mathematical Expression
Evaluate Mathematical Expression
You are given a string S representing a mathematical expression. The expression contains non-negative integers, binary operators +
, -
, *
, /
, and parentheses ( )
. Your task is to evaluate the expression and output the result as an integer.
Note that the division operator should truncate towards zero. For example, the expression \(3+5/2\) evaluates to \(5\).
The expression is guaranteed to be valid. Test cases include simple expressions, expressions with nested parentheses, and a mixture of all operators.
inputFormat
Input is provided via standard input (stdin) as a single line containing a mathematical expression.
outputFormat
Output the evaluated integer result of the expression to standard output (stdout).## sample
1+2
3