|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||128 MB||122||0||0||0.000%|
The formal methods team at your place of work has decided to experiment with very small functional language. They have, of course, specified it. The bad news is that you have to implement it. The good news is that you can do so in a programming language of your choice and a formal proof of the correctness of your implementation is not required. In the grand tradition of Lisp your implementation will take the form of an interpreter which accepts expressions, assignments and function definitions from the console. Function definitions are remembered and the functions may be used in subsequent expressions. Expressions are immediately evaluated, and the result is displayed at the console.
The input consists of a series of input lines, each holding an input action. No line has more than 100 characters. Actions can be of the following kinds:
Input should be processed, one line at a time, performing the requested action immediately, until the line with ‘exit’ is reached. The only data type processed by the language is integer. Values lie in the range -1,000,000 to 1,000,000 at all times. (The range is inclusive). The syntax for expressions is as follows. Operator precedence applies in the normal manner – evaluate factors, then terms and finally expressions.
White space should be ignored on all input lines, except in so far as it separates words. You can assume that all input is syntactically correct, that all function calls return (terminate), and that all expressions produce results in the permitted range. The total number of calls profiled on any one function line will never exceed 1,000,000.
Expression results should be reported on a line of their own, prefixed by ‘>> ‘ (two greater than signs and a single space).
Profile results should be reported with one line per function of the form ‘<identifier> calls: n1 n2 n3 … => nt ’ where ni is the number of calls for definition line i in order input, and nt is the total number of calls to the function (single spaced).
2 2 + 5 / 2 * 2 2 - 5 % 2 def fib(1) = 1 def fib(2) = 1 def fib(p) = fib(p-1) + fib(p-2) fib(1) profile fib(2) profile fib(3) profile fib(5) profile set x = 6 x * 4 + fib(x) def test(1) = 1 def test(2) = 1 def test(p) = (test(p-1) + test(p-2) + 23) % 1000 def test(2) = 10 test(3) profile exit
>> 2 >> 6 >> 1 >> 1 fib calls: 1 0 0 => 1 >> 1 fib calls: 0 1 0 => 1 >> 2 fib calls: 1 1 1 => 3 >> 5 fib calls: 2 3 4 => 9 >> 32 >> 25 fib calls: 3 5 7 => 15 test calls: 1 1 1 0 => 3