Interpreter
时间: 1ms 内存:64M
描述:
A certain computer has ten registers and 1,000 words of RAM. Each register or RAM location holds a three-digit integer between 0 and 999. Instructions are encoded as three-digit integers and stored in RAM. The encodings are as follows:
100means halt
2dnmeans set register d to n (between 0 and 9)
3dnmeans add n to register d
4dnmeans multiply register d by n
5dsmeans set register d to the value of register s
6dsmeans add the value of register s to register d
7dsmeans multiply register d by the value of register s
8dameans set register d to the value in RAM whose
address is in register a
9sa
means set the value in RAM whose address
is in register a to the value of register s
0dsmeans goto the location in register d unless
register s contains 0All registers initially contain 000. The initial content of the RAM is read from standard input. The first instruction to be executed is at RAM address 0. All results are reduced modulo 1,000.
输入:
Each input case consists of up to 1,000 three-digit unsigned integers, representing the contents of consecutive RAM locations starting at 0. Unspecified RAM locations are initialized to 000.
输出:
The output of each test case is a single integer: the number of instructions executed up to and including the halt instruction. You may assume that the program does halt.
示例输入:
299
492
495
399
492
495
399
283
279
689
078
100
000
000
000
示例输出:
16
提示:
参考答案:
文章评论