#C10665. Instruction Interpreter

    ID: 39895 Type: Default 1000ms 256MiB

Instruction Interpreter

Instruction Interpreter

This problem requires you to simulate a simple programming language that supports variable assignment and arithmetic operations. You are given a series of instructions where each instruction is one of the following commands:

  • SET: Assign an integer value to a variable. The format is SET X value.
  • ADD: Add the values of two variables and store the result in a third variable. The format is ADD R X Y which computes \( R = X + Y \).
  • SUB: Subtract the second variable from the first and store in a variable. Format: SUB R X Y meaning \( R = X - Y \).
  • MUL: Multiply the values of two variables. Format: MUL R X Y means \( R = X \times Y \).
  • DIV: Perform integer division of the first variable by the second. Format: DIV R X Y represents \( R = \lfloor X / Y \rfloor \).
  • PRINT: Output the value of the specified variable.
  • END: Terminate the processing of instructions.

All variables are represented by single uppercase letters (A-Z) and are initialized to 0. If a variable is used before being explicitly set, its value is assumed to be 0.

inputFormat

The input is given via standard input (STDIN) as multiple lines, where each line represents an instruction. The sequence of instructions terminates with a line containing END. You should read instructions until END is encountered.

outputFormat

For each PRINT instruction, output the value of the corresponding variable on a separate line to standard output (STDOUT).

## sample
SET A 10
SET B 20
ADD C A B
PRINT C
MUL D B C
PRINT D
SUB E D C
PRINT E
DIV F D B
PRINT F
END
30

600 570 30

</p>