← 返回 bytedance 的题目列表Basic Calculator II
类型:online_judge
Problem: Basic Calculator II
Given a string s representing a valid arithmetic expression containing non-negative integers, spaces, and operators +, -, *, /, evaluate the expression and return the result.
Rules & Constraints
The expression may contain spaces.
Operator precedence: * and / have higher precedence than + and -.
Operators of the same precedence are evaluated left-to-right.
Integer division truncates toward zero (e.g., 3/2 = 1, -3/2 = -1).
The input expression is guaranteed to be valid.
Input Format
One line: string s
Output Format
Output one integer: the evaluated result.
Constraints
1 <= len(s) <= 3e5
s consists of digits, spaces, and + - * /
Intermediate results fit in 32-bit signed integer
Examples
Input: 3+2*2 -> Output: 7 Input: 3/2 -> Output: 1 Input: 3+5 / 2 -> Output: 5
Example
Input
3+2*2
Output
7