13860 - The password ver2   

Description

Mr. Kuo is an adventurer. One day, he finds another secret room in a cave.

There is some hint to the password of this room.

 

Mr. Kuo is given a string S = s1s2...sN consisting of LR, l, and r.

At first, Mr. Kuo has a string A = "0", a number x = 1, and the cursor is on 0.

For each letter c in S:

  • If c is L, insert x to the left of the cursor, set cursor on x, and set x to x + 1.
  • If c is R, insert x to the right of the cursor, set cursor on x, and set x to x + 1.
  • If c is l, move the cursor to the far left.
  • If c is r, move the cursor to the far right.

 

The final contents of A is the password. Please help Mr. Kuo find the password.

 

For example, S = "rRlL", then:

  • s1 = r, move the cursor to the far right(0), x = 1, A = "0", cursor on 0
  • s2 = R, insert x(=1) to the right of the cursor(0), x = 2, A = "01", cursor on 1
  • s3 = l, move the cursor to the far left(0), x = 2, A = "01", cursor on 0
  • s4 = L, insert x(=2) to the left of the cursor(0), x = 3, A = "201", cursor on 2

 

This problem is partial judge, you have to finish the four functions:

  • addleft(int k): insert k to the left of the cursor
  • addright(int k): insert k to the right of the cursor
  • toleft(): move the cursor to the far left
  • toright(): move the cursor to the far right

(Don't forget to include "function.h" in you code!)

Input

The first contains an integer T -- the number of testcases.

Each of the following line contains a string S.

For testcase 1~3, 1 <= T <= 100, length of S <= 2e5, S contains only and R.

For testcase 4~6, 1 <= T <= 10, length of S <= 1000, S contains L,  Rl, and r.

For testcase 7~9, 1 <= T <= 100, length of S <= 2e5, S contains L,  Rl, and r.

Output

For each test case print a string A — the final contents of the password, seperated by spaces.

Sample Input  Download

Sample Output  Download

Partial Judge Code

13860.cpp

Partial Judge Header

13860.h

Tags




Discuss