|
||||||||||
Advanced CalculatorTime Limit: 14000/7000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 240 Accepted Submission(s): 17 Problem Description 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. Input 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. Output 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. Sample Input
Sample Output
Source | ||||||||||
|