#K15916. Taco: Perform Operations on Integers
Taco: Perform Operations on Integers
Taco: Perform Operations on Integers
You are given several test cases. In each test case, you are provided with an initial integer X and a sequence of operations. Each operation is either an addition (+) or a multiplication (*).
Your task is to perform the given operations sequentially on X and output the final result for each test case. Formally, for a test case with an initial value X and a series of operations op1, op2, ..., opK with corresponding values v1, v2, ..., vK, you must compute
$X_{final} = (((X \; op_1 \; v_1) \; op_2 \; v_2) \; ... \; op_K \; v_K)$
and output X_final
for each test case on a separate line.
inputFormat
The input is given from standard input (stdin
) and has the following format:
- The first line contains an integer T specifying the number of test cases.
- For each test case:
- The first line contains the initial integer X.
- The next line contains an integer K indicating the number of operations.
- The following K lines each contain an operation in the format:
op value
, whereop
is either+
or*
andvalue
is an integer.
outputFormat
For each test case, output the final result after performing all the operations. Each result should be printed on a new line to standard output (stdout
).
1
100
2
+ 50
* 2
300