#C12697. Evaluate Mathematical Expression
Evaluate Mathematical Expression
Evaluate Mathematical Expression
You are given a string representing a mathematical expression that may contain integers, the operators +
, -
, *
, /
, decimal points, and parentheses ( )
. The expression must be evaluated following the standard order of operations, i.e. PEMDAS (\(\mathrm{P}\)arentheses, \(\mathrm{E}\)xponents (not present in the input), \(\mathrm{M}\)ultiplication and \(\mathrm{D}\)ivision, \(\mathrm{A}\)ddition and \(\mathrm{S}\)ubtraction).
Your task is to read the expression from standard input (stdin), validate the expression for any invalid characters and balanced parentheses, and then compute and output the result to standard output (stdout). In the event of a division by zero or any other invalid expression, the program should produce an error output (for this contest problem, all the provided test cases will be valid).
inputFormat
The input consists of a single line containing a string that represents the mathematical expression. The expression may include spaces.
outputFormat
Output a single line containing the result of the evaluated expression. The result should be printed to standard output.
## sample2 + 3
5