시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 128 MB | 2 | 1 | 1 | 50.000% |
Hal has a symbolic calculator whose memory is organised as a list that can have at most 100 elements. Each element can contain an arithmetic expression. The calculator understands following commands:
List with two elements is given. The first element contains A and the second element contains B.
Write a program which will for given expression e generate a sequence of commands for Hal’s calculator that will, starting with given list and executing all commands of the sequence without any error as a result leave a list whose first and only element contain expression e.
An error occurs if list gets too long (attempt to add 101st element) or if there are not enough elements needed to perform a command. Commands DUP and DROP require that the first element has an expression; commands HASH, DOLLAR and SWAP require that the first two elements have expressions; command ROT requires that the first four elements of a list have expressions.
Program should generate any sequence of commands that as result leaves given expression. Number of commands in a sequence should not exceed 10000.
The first and only line of input file contains a given expression which is a sequence of characters A, B, #, $, (,) and nothing else (not even space characters).
Length of expression will always be 100 or less.
There will always be a solution to test data.
The output file should contain a sequence of commands generating given expression. Each line should contain one command.
Note: a solution needs not to be unique.
(B$A)
SWAP DOLLAR
(A$(A#B))
SWAP DUP DUP ROT HASH DOLLAR SWAP DROP
((A$B)#(B$A))
SWAP DUP DUP ROT ROT DROP DUP DUP ROT ROT DROP SWAP ROT ROT DOLLAR DUP ROT ROT ROT DROP SWAP DOLLAR HASH