#K3336. Evaluate Mathematical Expression
Evaluate Mathematical Expression
Evaluate Mathematical Expression
You are given a string that represents a mathematical expression. The expression contains non-negative integers and the operators +, -, *, and /. Your task is to compute and output the integer result of the expression. The operations should be evaluated following the standard operator precedence rules:
\( \text{Multiplication and Division have higher precedence than Addition and Subtraction.} \)
If the expression is invalid (e.g. contains illegal characters, an incomplete operator sequence, division by zero, or is empty), output None
.
Note: When division occurs, the result is converted to an integer by truncating the decimal part (i.e. using the built-in conversion to integer).
inputFormat
The input consists of a single line which is a string representing the mathematical expression. The expression can contain spaces.
outputFormat
Output a single line: the evaluated integer result of the expression or None
if the expression is invalid.
3+5*2
13