| Online MIPT programming contest | РУССКИЙ |
| <PREV Problem: | NEXT> |
< |
|---|
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#12 a:=1+2*3 a |
Output#19 |
Input#22 a:=b-b a |
Output#2error |
Input#33 b:=a*2 a:=(1+3)*3 b |
Output#324 |
Input#48 b:=a*2 a:=(1+3)*3 c:=a+b+d d:=a+c e:=(b-a) b c e |
Output#424 error 12 |
Author:
Voroztsov Artem
18 May 2003
© acm.mipt DevGroup The page was generated in 330ms |