<PREV Problem:
NEXT>
Solved by 165 users: ...
UserDateAttemptTimeCMSC
sb3ar24 apr 2008Ruby700.0452 
sb3ar24 apr 2008Ruby600.0454 
sb3ar24 apr 2008Ruby500.0456 
sb3ar03 may 2008Ruby800.0456 
yumeko22 sep 2011Lua101.45239 
LOD13 may 2017C++100.37403 
kage06 mar 2007C++100.01441 
david_it2118 apr 2008Ruby900.06454 
david_it2118 apr 2008Ruby800.06471 
adamg20 may 2006C++100.28496 
david_it2118 apr 2008Ruby700.05500 
JohnJones_00111 sep 2006C++100.01512 
Vladimir_Sitnikov06 nov 2005Java200.75513 
alex_rodin14 may 2007C++600.72516 
DAV21 feb 2010C++400.19545 
DAV21 feb 2010C++300.19547 
DAV21 feb 2010C++200.19561 
Languages
C++
102
FPC
25
Java
13
C
12
Kylix
8
Ruby
2
Lua
1
Python
1
Perl
1
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 

Arithmetica v1.3

Time limit = 5 seconds

You are the lead programmer of Walfram Research Corp. Your task is to write the program Arithmetica v1.3. In this version you should realize functions without parameters. Functions with parameters will be realized in the version 1.5. Arithmetica 1.3 must work in the folowing way:

Input. The first line of input contains integer N (N < 100). Then N lines follow. Each line is a command. Command is either definition of a function or an identifier.

alpha	   ::= a-zA-Z
numeric	   ::= 0-9
command    ::= identifier | definition
definition ::= identifier ':=' expression
identifier ::= alpha +
expression ::= '(' expression ')' | integer_number | identifier | expression ('+' | '*' | '-') expression
integer_number ::= '-' ? numeric+

If command is definition, then nothing should be output.

If command is identifier,then it should be interpreted as requests to calculate function: "calculate the value of the function and output result".

Each function should have no more than one definition. In input definitions go first, requests to calculate functions follow them. The length of each input line is less than 1000.

Output. For each request to calculate a function your program should output one line with the result of calculation. If the recursion depth of the requested function is infinity or some envolved functions (identifies) are not defined, then the result should be 'error'. Otherwise the result is numerical value of the function.

It is known that all numbers and values of functions are less than 230 in absolute value.

Input#1
2
a:=1+2*3
a
Output#1
9


Input#2
2
a:=b-b
a
Output#2
error

Input#3
3
b:=a*2
a:=(1+3)*3
b
Output#3
24

Input#4
8
b:=a*2
a:=(1+3)*3
c:=a+b+d
d:=a+c
e:=(b-a)
b
c
e
Output#4
24
error
12

Author:
Voroztsov Artem
18 May 2003

<PREV | Problem set | Search related messages | NEXT>


© acm.mipt DevGroup
The page was generated in 200ms

SW soft NIX
ID = 18.232.51.69