Expression with precedence
Input
"3+2*2"
Output
7
Multiplication before addition: 2*2=4, 3+4=7.
Full lesson preview
Parse and evaluate an infix arithmetic expression with parentheses and +,-,*,/ using two stacks.
Problem statement
Task
Examples
Input
"3+2*2"
Output
7
Multiplication before addition: 2*2=4, 3+4=7.
Input format
Output format
Constraints
Samples
Input
" (1+(4+5+2)-3)+(6+8) "
Output
23
Evaluate inner parentheses and apply operations in correct order.