|Online MIPT programming contest||РУССКИЙ|
Time limit = 5 secondsYou 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.
2 a:=1+2*3 a
2 a:=b-b a
3 b:=a*2 a:=(1+3)*3 b
8 b:=a*2 a:=(1+3)*3 c:=a+b+d d:=a+c e:=(b-a) b c e
24 error 12
18 May 2003
© acm.mipt DevGroup
The page was generated in 200ms