#P2788. Evaluate Mixed Addition and Subtraction Expressions
Evaluate Mixed Addition and Subtraction Expressions
Evaluate Mixed Addition and Subtraction Expressions
HansBug has finally reached the last math problem, but his braincells and RP are exhausted! In front of him is a cluttered arithmetic expression consisting solely of additions and subtractions. Your task is to compute the result of the given arithmetic expression.
The expression is a string that contains non-negative integers and the operators + and - only. There are no spaces in the expression. Note that numbers may have more than one digit.
You need to evaluate the expression from left to right and output the result.
Formally, if the expression is given by \[ E = a_1 \; op_1 \; a_2 \; op_2 \; a_3 \; \dots \; op_{n-1} \; a_n, \] where each \(a_i\) is a non-negative integer and each \(op_i\) is either \(+\) or \(-\), then compute: \[ ans = a_1 \; op_1 \; a_2 \; op_2 \; a_3 \; \dots \; op_{n-1} \; a_n. \]
inputFormat
The input is a single line, which contains a non-empty arithmetic expression consisting of digits (0-9) and the characters '+' and '-'. The expression does not contain any spaces. It is guaranteed that the expression is valid.
outputFormat
Output a single integer: the evaluated result of the arithmetic expression.
sample
3+2-1
4