当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

4594:Script Z

题目描述
Recently, Programmer Zero have made a new script programming language, named Script Z. He is so proud of his new language, that he wrote many programs in Script Z. Unfortunately, he found his script works strangely, and he had no idea what happened. So he wants you to write a Script Z Interpreter for him.
Here are some information about Script Z:
1. Variable: All variable names start with symbol $, and the name of the variable should only contains letters (upper case and lower case), numbers and underlines (_). The first character of the number can be any legal character for the variable. For example, $a $c $t $0 $2 $_ are all legal variable names, while $0-a, $0%b are illegal ones. Variables can be assigned many times during the processing of the script. The length of variable name is no larger than 32. (Does not include the first $ symbol, so the max length of variable name will be 33 with symbol $).
2. Constant: All constant names must start with letters (upper case and lower case), and should only contains letters (upper case or lower case), numbers and underlines (_). For example, A B A10 B_123 are legal constant names, while 5A 4_b are illegal ones. Constants can be assigned at most once. The length of constant name is no larger than 32.
3. White spaces: Spaces (' ', ord(' ') == 32) and tabs ('\t', ord('\t') == 9).
4. Lines: All lines are terminated with character LF('\n', ord('\n') == 10). Each line should be a statement or a blank line.
5. Statement: There will be exactly one statement in one line (except blank lines). The white spaces at the beginning and the end of the statement should be ignored.
6. Blank lines: One line that contains only white spaces or no character.
7. Data Types:
Integer: All integer contains only numbers ([0-9]). The length of integer is not larger than 100.
String: All string values are quoted with double quotes ("), and there won’t be any other double quotes in the string value. All characters in the string are printable[ We call a character printable, if and only if the ASCII code of the character is not smaller than 32 and is not larger than 127.]. The length of string (without double quotes) is not larger than 100. (The length is not larger than 102 if with double quotes.)
There are 5 kinds of statement in Script Z:
1. Assignment:
$Variable = Value
Constant = Value
Notice: there may be none or any number of white spaces before and after the equal sign (=).
The value can be either an integer or a string, and won’t be a reference of variable or constant.
The following assignment are legal:
$a = 1
$b = 2
$b = 3
$_ = "a"
$ok = "true"
$long = 123456789012345678901234567890
CONST = 1
CONST_STRING = "sample"
EMPTY = ""
And these are illegal:
$a = $b
CONST_STRING = a
BOOLEAN = false
FLOAT = 1.5
EMPTY =
2. Output:
Print $Variable
Print Constant
There are at least one white space between Print and variable or constant. For each output statement, your program should print the value of the variable or the constant. No double quotes are needed if the value is string. If the variable is undefined, you should print NULL, and if the constant is undefined, you should print the name of the constant. And also remember to take a look of error reporting part.
3. Dump:
Dump $Variable
Dump Constant
There are at least one white space between Dump and variable or constant. For each dump statement, your program should print the type and the value of the variable or the constant. Double quotes are needed if the value is string. If the variable is undefined, you should print NULL, and if the constant is undefined, you should regard the constant name as a string to be the value of the constant. And also remember to take a look of error reporting part. Use the format in sample output.
4. Error reporting:
Errmsg ON|OFF
There are at least one white space between Errmsg and ON or OFF. Errmsg ON turns on the error reporting while Errmsg OFF turns off. Error reporting is turned on if not specified. If error reporting is turned on, after each statement, you should:
(1) You should print one line if there are undefined variable in Print or Dump statement:
NOTICE: Undefined Variable ${var_name}.
You should replace ${var_name} with the name of variable.
(2) You should print one line if there are undefined constant in Print or Dump statement:
NOTICE: Undefined Constant {const_name}.
You should replace {const_name} with the name of constant.
(3) You should print one line if an assignment are trying to assign an assigned constant:
WARNING: Constant {const_name} Already Defined!
You should replace {const_name} with the name of constant. And you should ignore this assign statement even if the error reporting is turned off (The value of the constant should not be changed).
5. Terminate:
Panic
Your program should print one line and exit after this statement:
Script was KILLED.
You should ignore all statements after the terminate statement.
输入解释
Input contains multiple test cases. The first line of the input contains exactly one integer T, which means the number of test cases. (T <= 10)
For each test case, the first line contains exactly one integer N, which means the lines of the script. (N <= 100000)
The next N lines, contains the statement of the script. Each line is no longer than 256 characters.
You are guaranteed that all statement, variable name, constant name are legal.
输出解释
For each test case, print the output of the script.
Use one blank line to split test cases, no blank line should exist at the end of the last test case. (Only one line terminator '\n')
输入样例
2
13
Errmsg ON
$a = 1
$b = 2
$c = 3
Print $a
Print $d
Dump $c
Errmsg OFF
Print $_
Print OK
Panic
Errmsg ON
Print A
13
Errmsg ON
$A = 3
$B = 5
Print $a
Print $B
A = 5
A = 10
Print A
Errmsg OFF
B = ""
B = "A"
Dump B
Dump C
输出样例
1
NULL
NOTICE: Undefined Variable $d.
integer: 3
NULL
OK
Script was KILLED.

NULL
Notice: Undefined Variable $a.
5
WARNING: Constant A Already Defined!
5
string: ""
string: "C"
提示
The problem itself is easy of course. But some of the test cases of this problem are strange and annoying. Be careful!
来自杭电HDUOJ的附加信息
Recommend zhuyuanchen520

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-4594

最后修改于 2020-10-25T23:14:59+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
20000/10000MS(Java/Others) 131072/65536K(Java/Others)