Solved by 165 users: ...
UserDateAttemptTimeCMSC
sb3ar`24 apr 2008`Ruby700.0452
sb3ar`24 apr 2008`Ruby600.0454
sb3ar`24 apr 2008`Ruby500.0456
sb3ar`03 may 2008`Ruby800.0456
yumeko`22 sep 2011`Lua101.45239
LOD`13 may 2017`C++100.37403
kage`06 mar 2007`C++100.01441
david_it21`18 apr 2008`Ruby900.06454
david_it21`18 apr 2008`Ruby800.06471
adamg`20 may 2006`C++100.28496
david_it21`18 apr 2008`Ruby700.05500
JohnJones_001`11 sep 2006`C++100.01512
Vladimir_Sitnikov`06 nov 2005`Java200.75513
alex_rodin`14 may 2007`C++600.72516
DAV`21 feb 2010`C++400.19545
DAV`21 feb 2010`C++300.19547
DAV`21 feb 2010`C++200.19561
 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 DevGroupThe page was generated in 180ms