# | Problem | Pass Rate (passed user / total user) |
---|---|---|
13342 | Domo to omoD |
|
13383 | Cardcaptor Sakura2 |
|
Description
Domo is a brilliant dog. When he gets enough sleep, he will be happy.
Unfortunately, he got some problems with his homework this evening. He mistakes 'postfix' as 'prefix', which makes him can't go to sleep until he corrects his homework.
Given a prefix expression, please convert it to the postfix expression or Domo will be punished since he didn't finish his homework.
Prefix: The operator appears in the expression before the operands. Simply of the form (operator operand1 operand2).
Postfix: The operator appears in the expression after the operands. Simply of the form (operand1 operand2 operator).
Take an Example: (A+B) * (C-D)
Prefix: * + A B - C D
Postfix: A B + C D - *
This problem is testing your recursion skill, so don't consider if the expression is valid or not (such as divided by zero)
Input
The first line contains a prefix expression, in which each element is separated with a blank.
It's guaranteed that the number of elements will not exceed 500.
Output
Print the corresponding postfix expression from the given prefix expression, and separate each element with a blank.
You don't need to print a newline character in this problem, I apologize for any inconvenience.
Remember to print a newline character at the end of each line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
The problem is modified from 13361 - Cardcaptor Sakura.
You have to implement two more instructions (1) shiftleft (2) shiftright in this problem.
There are 10 tables (indexed from 0 to 9) and no cards on them initially.
Given a command S, Sakura has to follow the instructions below:
(1) print: print the status of each table with the format :"table_idx: cards_on_the tables\n", e.g. "0: 1 3 3 4 5\n".
Note that if there are no cards, print "No card".
(2) all num len : Place len cards on each table, and the value on each card is num .
For example, the instruction "all 3 4" changes the status of each table to "table_idx: 3 3 3 3\n";
(3)
place table_idx len
integer_sequence
: Place a stack of cards on table table_idx. len means the number of cards in the stack. An integer sequence integer_sequence of length len is given, in which each integer means the value on the placed card.
For example, the instruction will be like:
place 2 3
3 2 1
And the status of Table_2 will become:
2: 3 2 1
Note that if there are cards already on the target table, the status will be overridden.
(4) swap table_a table_b: Swap the cards on table_a and table_b.
For example:
If the origin status of table 0 and table 1 are:
0: 1 2 3
1: 4 5 6
after "swap 0 1", the status of the two tables become:
0: 4 5 6
1: 1 2 3
This instruction is valid even if one of the tables is empty.
(5) clear: Clean all the tables.
(6) exit: terminates
(7) shiftleft: Move each pile of cards to its left. For table 0, move the cards to table 9.
For example:
If the origin status of tables are:
0: 1 1 1
1: 2 2 2
2: 3 3 3
3: 4 4 4
4: 5 5 5
5: 6 6 6
6: 7 7 7
7: 8 8 8
8: 9 9 9
9: 10 10 10
afeter shiftleft, it'll become:
0: 2 2 2
1: 3 3 3
2: 4 4 4
3: 5 5 5
4: 6 6 6
5: 7 7 7
6: 8 8 8
7: 9 9 9
8: 10 10 10
9: 1 1 1
(8) shiftright: Move each pile of cards to its right. For table 9, move the cards to table 0.
For example:
If the origin status of tables are:
0: 1 1 1
1: 2 2 2
2: 3 3 3
3: 4 4 4
4: 5 5 5
5: 6 6 6
6: 7 7 7
7: 8 8 8
8: 9 9 9
9: 10 10 10
afeter shiftright, it'll become:
0: 10 10 10
1: 1 1 1
2: 2 2 2
3: 3 3 3
4: 4 4 4
5: 5 5 5
6: 6 6 6
7: 7 7 7
8: 8 8 8
9: 9 9 9
Input
Commands separated by a newline character.
Note that:
1 <= the value of each card <= 13
1 <= number of cards on each table <= 10000
Note that only testcase 1, 5, and 6 contains shiftleft and shiftright.
Output
Status of each table.