问题1316--Push-pop-push-pop

1316: Push-pop-push-pop

[命题人 : ]
时间限制 : 1.000 sec  内存限制 : 128 MB

提交

题目描述

We all know that:
1. The stack is a data structure that can only push an element from the ending and pop an element from the ending.
2. The queue is a data structure that can only push an element from the ending and pop an element from the beginning.
For example:
1. A stack [1, 2, 3], execute operation push 4, it becomes [1, 2, 3, 4]
2. A stack [1, 2, 3], execute operation pop, it becomes [1, 2]
3. A queue [1, 2, 3], execute operation push 4, it becomes [1, 2, 3, 4]
4. A queue [1, 2, 3], execute operation pop, it becomes [2, 3]
Now, there is an empty sequence, I will give you Q instructions, you should push or pop an element from this sequence which is treated as a stack or a queue. Specially, if popping from an empty sequence, nothing will happen.

输入

A unsigned integer Q, and then Q lines:
There are some different formats:
1. s x. This means pushing the element x into the sequence which is treated as a stack.
2. S. This means popping the element from the sequence which is treated as a stack.
3. q x. This means pushing the element x into the sequence which is treated as a queue.
4. Q. This means popping the element from the sequence which is treated as a queue.
5. d. Output the sequence at the current time.
x is always an integer.

输出

Output the sequence at the current time when the line of input is d. If the sequence is empty, print "empty"(without quotation marks).

样例输入 Copy

10
q 1
s 2
q 3
s 4
d
Q
S
d
s 5
d

样例输出 Copy

1,2,3,4
2,3
2,3,5

提示

Values' range:
|x| <= 109
Q <= 50000

来源/分类