#K11286. Arithmetic Expression Evaluator
Arithmetic Expression Evaluator
Arithmetic Expression Evaluator
You are given a string that represents an arithmetic expression containing nonnegative integers, the operators \(+, -, \times, \div\), and possibly parentheses. Your task is to evaluate the expression according to the standard operator precedence rules (i.e. \(\text{PEMDAS}\) or \(\text{BODMAS}\)).
The expression may include extra whitespace, which should be ignored. When performing division, the result may be a floating point number. If the evaluated result has no fractional part, output it as an integer; otherwise, output the floating point value.
inputFormat
The input consists of a single line read from standard input (stdin
). This line contains the arithmetic expression. For example, you may receive an input like:
3+2*2
outputFormat
Output a single value to standard output (stdout
), which is the result of the evaluated arithmetic expression. The output should be an integer if the result is whole or a floating point number if there is a fractional part.
3+2*2
7