F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Advanced Calculator

Time 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
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);
 

Sample Output
2 -12.000000 divided by ZERO
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 18:36:26, Gzip enabled