#C12856. Arithmetic Operation Evaluator
Arithmetic Operation Evaluator
Arithmetic Operation Evaluator
You are given a sequence of arithmetic operations to be performed sequentially starting from an initial value of \(0\). Each operation is provided as a pair consisting of an operation name and an integer. The supported operations are:
- add: \(result = result + number\)
- subtract: \(result = result - number\)
- multiply: \(result = result \times number\)
- divide: Performs integer division \(result = \lfloor result / number \rfloor\). If division by zero is attempted, the program should output
undefined
.
If an unsupported operation is encountered, the program must output the error message: Unsupported operation: <operation>
. The final result (or error message) should be printed to stdout.
inputFormat
Input is read from standard input (stdin). The first line contains an integer (n), representing the number of operations. Each of the following (n) lines contains an operation (a string) and an integer, separated by a space.
outputFormat
Output the final result after applying all operations sequentially. If a division by zero occurs, output undefined
. For an unsupported operation, output the error message in the format: Unsupported operation: <operation>
.## sample
4
add 5
multiply 3
subtract 2
divide 3
4