1316: Push-pop-push-pop

内存限制:128 MB 时间限制:1.000 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:45 通过:8 通过率:17.778%

题目描述

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).

输入样例 复制

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

输出样例 复制

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

数据范围与提示

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

分类标签