#K68762. MiniScript Interpreter

    ID: 32937 Type: Default 1000ms 256MiB

MiniScript Interpreter

MiniScript Interpreter

You are given a program written in a simplified language called MiniScript. The program consists of a series of commands, and your task is to simulate the execution of these commands using a single register, initially set to 0.

The commands are as follows:

  • increg: Increase the register's value by 1.
  • decreg: Decrease the register's value by 1.
  • printreg: Print the current value of the register to stdout.

For each printreg command, the current value of the register is printed on a new line. If an unknown command is encountered, the program should raise an error (or in some implementations, terminate abnormally).

The register updates follow the formula: $$register \leftarrow register + \Delta$$ where \( \Delta = 1 \) for increg and \( \Delta = -1 \) for decreg. Initially, \( register = 0 \).

inputFormat

The input is given via stdin in the following format:

  1. The first line contains an integer n indicating the number of commands.
  2. The next n lines each contain a single command, which can be increg, decreg, or printreg.

outputFormat

For each printreg command in the input, print the current value of the register on a new line to stdout. If all commands are executed without error, all outputs must be printed in order.

## sample
3
increg
increg
printreg
2

</p>