← 返回 openai 的题目列表Toy Language Interpreter
类型:online_judge
Problem Description
Implement a simple interpreter to execute basic toy language instructions. Your task is to parse and execute the following types of commands:
Variable Assignment: x = 5, assign an integer value to a variable.
Addition Operation: x = x + 2, support simple integer addition.
Print Instruction: PRINT x, print the value of a variable to the console.
Sample Input
x = 5
x = x + 2
PRINT x
Sample Output
7
Constraints
Variable names are single lowercase letters.
Operands are integers.
Parentheses are not supported.
At most 50 instructions.
Test Cases
x = 3\ny = 4\nPRINT x should output 3.
a = 1\na = a + 1\nPRINT a should output 2.
x = 10\nx = x + x\nPRINT x should output 20.
z = 0\nz = z + 5\nPRINT z should output 5.
y = 5\nPRINT y\ny = y + 3\nPRINT y should output 5\n8.
Example
Input
x = 3\ny = 4\nPRINT x