#K95352. Evaluate Arithmetic Expression
Evaluate Arithmetic Expression
Evaluate Arithmetic Expression
You are given an arithmetic expression as a string containing non-negative integers and the operators + and -. In this problem, you must evaluate the expression by processing it from left to right, ignoring the standard operator precedence. That is, instead of first calculating multiplication or addition by standard rules, you evaluate each operator sequentially as they appear.
For example, the expression 3+2-5
is processed as follows:
\(\, 3 + 2 = 5 \) and then \( 5 - 5 = 0 \).
Your task is to implement a function that computes the result of such arithmetic expressions.
inputFormat
Input Format: A single line containing a string representing an arithmetic expression. The expression consists of digits (0-9) and the operators '+' and '-' without any spaces. The input is provided via stdin
.
outputFormat
Output Format: Print a single integer on a new line representing the result of evaluating the arithmetic expression from left to right. The output should be written to stdout
.
3+2-5
0