#C7238. Left-to-Right Arithmetic Expression Evaluation
Left-to-Right Arithmetic Expression Evaluation
Left-to-Right Arithmetic Expression Evaluation
You are given an arithmetic expression containing non-negative integers and the operators +
and -
. Unlike standard arithmetic rules, you must evaluate the expression strictly from left to right, without taking into account the conventional operator precedence.
For example, the expression 3 + 5 - 2 should be evaluated as follows:
Your task is to compute the result for each expression provided in the input.
The input begins with a line containing an integer T representing the number of test cases. Each of the following T lines contains an arithmetic expression. For each expression, output the calculated result on a new line.
inputFormat
The input is read from stdin and consists of multiple lines:
- The first line contains an integer T (1 ≤ T ≤ 100), the number of test cases.
- Each of the next T lines contains an arithmetic expression composed of non-negative integers and the operators '+' and '-'. The tokens in the expression are separated by spaces.
Note: The operations should be performed in the order they appear (left-to-right evaluation) regardless of the normal operator precedence.
outputFormat
For each test case, output a single line containing the integer result of the evaluated expression. The results should be printed to stdout, one per line, in the same order as the corresponding test cases.
## sample2
3 + 5 - 2
10 - 4 + 7
6
13
</p>