Loading...
Loading...
Loading...
Evaluate an arithmetic line with non-negative integers and the operators + - * /. Multiplication and division happen before addition and subtraction. Division truncates toward zero. Spaces may appear anywhere between tokens. The divisor is never zero.
Example 1
Input
2+3*4
Output
14
Multiply first: 2 + 12 = 14.
Example 2
Input
14 - 6 / 4
Output
13
Try the problem first. Open one hint at a time.
Keep a stack of terms. Remember the operator that came before the current number.
+ pushes the number, - pushes its negative, * and / change the top term.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor