#K65022. Simple Expression Evaluator
Simple Expression Evaluator
Simple Expression Evaluator
You are given a mathematical expression as a string expr consisting only of positive integers, and the operators + and -. Your task is to evaluate the expression and print the result.
The expression follows the format:
\(expr = number \; ( ( '+' | '-' ) \; number )^*\)
For example, when expr = "12+34-5+6"
, the output should be 47
. The expression is guaranteed to be valid and does not contain any spaces.
inputFormat
The input consists of a single line containing a non-empty string expr
which represents the mathematical expression. The expression contains only digits (0-9) and the operators '+' and '-'.
outputFormat
Output a single integer which is the result of the evaluated expression.
## sample12+34-5+6
47