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

建议使用的浏览器:

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

5553:Advanced Calculator

题目描述
When Marry was in fourth grade, she made a simple calculator program to help her doing elementary arithmetic. But when she went up to fifth grade, Marry felt the old program would not meet her new requirement, so she decided to design an advanced calculator. You can input some code into this program and then it executes and gives you results. Since this code looks like the C programming language, Marry called these code: C---.

C--- contains two types of variables: 32-bit signed integer “int” and 64-bit signed float numbers “double”. The name of variables consists of English letters and numbers, but the first character must be a letter. The constants also have two types like the variables. Only constants containing the decimal mark “.” are treated as float numbers. For example, 3 is considered an integer, but 3.0 is a float number. Besides, the float numbers won’t use scientific notation.

A C--- program consists many lines, each line only has one single sentence and ends up with a semicolon. There are two parts in a C--- program. The beginning of a program is several lines of variable statements. The way to state a variable is the same as it in C programs, e.g. “int a;” or “double b;”, except that there are no initial values. A variable name consists of no more than twenty letters and all values will be set to zero initially. It should be noticed that not all C--- programs should contain variable statements.

The remaining part consists of some sentences, and each of them is an expression or output command (no variable statements appear). An expression may or may not have assignment operation. The output command is “print(x)”. It will print the value of $x$, which is a variable or constant, to the standard output stream on a single line. If $x$ is an integer, the output should display $x$ as an integer, otherwise display it as a float with 6 decimal places. In addition, no variable is named “print”.
The operators used in C--- program includes:

left parenthesis:  “ (
right parenthesis:  “)
assignment:  “=
plus:  “+
minus:  “-
multiplication:  “*
Division:  “/

The calculation methods and priority are same to C programs in terms of calculate methods and priority. It should be noticed that when operating an integer along with a float number, the integer will be transferred to a float number implicitly. Also, when a float number was assigned to an integer variable, the decimals of float number will be lost. These rules for implicit conversion are the same as C language. The value and type of an assignment expression “x=y” equal to $x$.

Now, you need to help Marry to develop this advanced calculator program, and then execute some C--- codes to validate the correctness.

There will be no empty lines but may be some extra blank spaces. We ensure that input program code is legal but there may be “divided by ZERO” runtime error. If the error happens, print single line of “divided by ZERO” and terminate the execution.
输入解释
The first line of input contains an integer $N$, which represents the number of lines of the C---code ($N≤10000$). The next $N$ lines contain the C— program. The number of characters in each line is not greater than 1000.
输出解释
For each “print” command, output the result according to the above specification. When “divided by ZERO” error occurs, output “divided by ZERO” in a single line and terminate the execution.
输入样例
12
int a;
double x,y;
int b,c,d;
a=5.5;
x=y=(1+a)*6.44;
a+4;
a=a/2;
print(a);
y=(c+6)*-(1+1);
print(y);
d=a/(2/5);
print(d);
输出样例
2
-12.000000
divided by ZERO
来自杭电HDUOJ的附加信息
Recommend wange2014

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

源链接: HDU-5553

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

共提交 0

通过率 --%
时间上限 内存上限
14000/7000MS(Java/Others) 262144/262144K(Java/Others)