ZOJ Problem Set - 3683
In order to teach some small FatSheep programming, the Big FatSheep designed a very simple language called Simple Language. After teaching some small FatSheeps, the big FatSheep received several program written by the Simple Language. But the big FatSheep is too busy that he doesn't have time to write the simulation program to run those programs. So he gives you the task to write the simulation program.
The Simple Language is really simple.
<NUM> is a signed 32bit integer. If the last character is D|B|H means the <NUM> is in base-10|2|16, the base-10 is default.
The Simple Language has 1024 variables (each variable is a signed 32bit integer, and its initial value is 0), numbered from $0 to $1023. And $0 is always 0. All the changes to $0 should be ignored. All variables can also be represented by base-2, base-10, base-16. For example $10 can also be $10D, $1010B, $AH, $aH.
The Simple Language can write an instruction in a line. If you want to write many instructions in a line, you could use ';' to separate them.
The Simple Language supports annotate. If you write a '#' in a line, all the character in the line and after '#' will be ignored.
SETTAG <TAG> to set a tag, <TAG> is a string contains '0'-'9', 'a'-'z' and 'A'-'Z'. In a program, all the tags should be unique. And <TAG> can appear at any place of the program.
GOTO <TAG> : jump to the place where the <TAG> set and continue, even if the SETTAG <TAG> is after the GOTO <TAG>.
IF <VAR> <TAG_1> <TAG_2> : if <VAR> > 0 then jump to the place where the <TAG_1> set and continue, else jump to the place where the <TAG_2> set and continue.
Other instructions is in the table. <TAG> is a tag. <VAR> is a variable. <DAT> is a variable or <NUM>.
There are multiple test cases. For each test case:
The first line contains one integer N(1 ≤ N ≤ 1000), indicating the simple language program has N lines.
The following N lines indicate the simple language program. And the length of each line is no more than 10000.
We guarantee that the program will finally end and the program can run successfully.
For each program, output the result of the simple language program.
Ouput a blank line after each test case.
5 SET $10 100B#Hello World!^_^ PRINT $10 ADD $10B $10 1 PRINT $2 SET $10B 0;PRINT $2 2 SET $1 5;SETTAG FS;PRINT $1;SUB $1 $1 1; IF $1 FS END;SETTAG END
4 5 0 5 4 3 2 1
For base-16 number, lowercase and uppercase are both available.
Author: LU, Yi
Contest: ZOJ Monthly, January 2013