#K84762. Evaluate Fully Parenthesized Expression
Evaluate Fully Parenthesized Expression
Evaluate Fully Parenthesized Expression
You are given a fully parenthesized arithmetic expression that can include the operators +, -, *, and /. The expression will be composed of non-negative integers and valid arithmetic operations. The division operator performs integer division (i.e. the result is the integer part of the quotient). Your task is to evaluate the expression and print the resulting integer.
The arithmetic expression is guaranteed to be valid. Note that each operation is contained within parentheses. For example, an input like ((2+3)*(5-2))
should output 15
.
Note: All operators follow the standard precedence, but the use of parentheses makes the order of evaluation explicit.
Hint: You may consider converting the infix expression into Reverse Polish Notation (RPN) using the Shunting-yard algorithm and then evaluate the RPN expression, or utilize a recursive descent parser.
inputFormat
The input consists of a single line containing a fully parenthesized arithmetic expression. The expression includes integers and operators (+, -, *, /) without any spaces.
outputFormat
Output a single integer which is the result of evaluating the given arithmetic expression using integer division for the '/' operator.## sample
((2+3)*(5-2))
15