lightoj1212

maksyuki 发表于 oj 分类,标签:
0

1212 - Double Ended Queue

pushLeft(): inserts an item to the left end of the queue with the exception that the queue is not full.A queue is a data structure based on the principle of 'First In First Out' (FIFO). There are two ends; one end can be used only to insert an item and the other end to remove an item. A Double Ended Queue is a queue where you can insert an item in both sides as well as you can delete an item from either side. There are mainly four operations available to a double ended queue. They are:

  1. pushRight(): inserts an item to the right end of the queue with the exception that the queue is not full.
  2. popLeft(): removes an item from the left end of the queue with the exception that the queue is not empty.
  3. popRight(): removes an item from the right end of the queue with the exception that the queue is not empty.

Now you are given a queue and a list of commands, you have to report the behavior of the queue.

Input

Input starts with an integer T (≤ 20), denoting the number of test cases.

Each case starts with a line containing two integers n, m (1 ≤ n ≤ 10, 1 ≤ m ≤ 100), where n denotes the size of the queue and m denotes the number of commands. Each of the next mlines contains a command which is one of:

pushLeft x        pushes x (-100 ≤ x ≤ 100) in the left end of the queue

pushRight x      pushes x (-100 ≤ x ≤ 100) in the right end of the queue

popLeft             pops an item from the left end of the queue

popRight           pops an item from the right end of the queue

 

Output

For each case, print the case number in a line. Then for each operation, show its corresponding output as shown in the sample. Be careful about spelling.

Sample Input

Output for Sample Input

13 8pushLeft 1pushLeft 2pushRight -1pushRight 1

popLeft

popRight

popLeft

popRight

Case 1:Pushed in left: 1Pushed in left: 2Pushed in right: -1The queue is fullPopped from left: 2

Popped from right: -1

Popped from left: 1

The queue is empty

 

 

题目类型:双端队列

算法分析:直接使用STL中的deque模拟即可,只不过还要动态维护一个队列中元素个数cnt