|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||128 MB||0||0||0||0.000%|
Your job, should you choose to accept it, is to write an interpreter for a small list calculator.
Input will consist of various expressions, which you evaluate.
Operators (from most tightly bound to least tightly bound). Brackets (), Unary operators, Array Slicing, Binary operators, list concationation.
The Unary operators (*,/,+,-) continuously remove the first two items of the list, and replace them with the result of the operator being applied. For example +(1:2:4) takes 1 and 2 off the front of the list, applies "+" to them, to get 3 which is placed on the front of the list leaving +(3:4), again we take the first two items, remove them, apply +, and insert the result into the front of the list +(7). Now the list has fewer than two items so we return the list 7. *,/,+,- are multiplication, division, addition and subtraction respectively. There is no unary minus on numbers.
Array slicing is done with the [begin:end] operator applied as a postfix to an expression. Items are 0 indexed and include the beginning item but don't include the end item. Thus (1:2:3:4:5)[1:3] is 2:3. The begin or end may be omitted and is expected to mean all items from the beginning or all items until the end (respectively).
Binary operators are applied to the first element of both lists, then the second element and so on. If one list is shorter than the other, then the shorter list is padded with its last item until both lists are the same length. Thus (1:2:3)+(4:5) is (5:7:8). Note that applying a binary operator to an empty list produces an empty list.
List concatenation is provided with the : operator. Standalone numbers are assumed to be a list of a single item. All numbers are assumed to be integers. None of the expressions will cause a division by zero.
Assignment is provided with the = operator. Variables are always single letters, case sensitive, and are never redefined.
Input will be terminated with a line starting with a "#".
The print command will output the result of an expression on a line by itself to standard out. Lists have items separated with a : with no spaces. The maximum number of items to be output will be no more than 15.
print +(1:2:4) print (1:2:3:4:5)[1:3] print (1:2:3)+(4:5) N=1:(N+1) E=2*N print E[:5] print +E[:10] F=1:1:(F+F[1:]) print F[:10] #
7 2:3 5:7:8 2:4:6:8:10 110 1:1:2:3:5:8:13:21:34:55