# | Problem | Pass Rate (passed user / total user) |
---|---|---|
12668 | Text Editor - Linked List Version |
|
12680 | Card Magic |
|
13134 | Band Ya Rou Ze |
|
13438 | Lucky money 1 |
|
Description
Modified from 10389 - text editor
In this problem we simulate a simple text editor. Given a series of keyboard input, output the final text content. Initially, the text content is empty and the cursor is at the beginning of the line. The user can:
-
Insert a lower-case alphabet ('a-z') before the cursor, denoted as a lower-case alphabet.
-
Erase an alphabet before the cursor, denoted as
B
. -
Move the cursor to the right one character at a time, denoted as
R
. -
Move the cursor to the left one word at a time, denoted as
L
.
Hints
In this problem, you are asked to use doubly linked list to reduce the time complexity. Three typical implementations as follows are possible. You can choose your favorite one, e.g., Impl 1 or Impl 2.
Remember to free memory when a linked list node is deleted. If you get Runtime Error
on test case, probably there is something wrong with the pointers or there is memory leak in your program.
Make sure the time complexity is O(1) for each operation, otherwise you may get Time limit exceed
Input
The first line is an integer T (1 <= T <= 50), meaning that there are T subtasks in the input.
In each subtask, there are two lines. The first line is an integer N(1<= N <= 106), being the length of the series of keyboard input. The next line is a string of length N, being the series of keyboard input.
It is guaranteed that L
and B
will not occur when the cursor is in the left-most position, R
will not occur when the cursor is in the right-most position.
Output
For each subtask, output the final text content in a single line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Mr. Lu is a famous magician. There’s a poker magic tutorial on his youtube channel.
There’re N stacks of cards on the table at begining.
And then, Mr. Lu make M actions on these card stacks.
There’s only two kinds of actions Merge and Cut:
- Merge x y: put the x-th card stack on the top of y-th card stack.
- Cut x i: cut the x-th card stack into two stacks. One is the card stack contains ( 1~i )-th cards of original stack. The other one is the remaining. The former’s index will be x, the latter’s will be (x+1)
- The indexes of stacks and cards will be changed after Merge and Cut.
For example:
As a lazy CS student, you only focus on the result.
Therefore, you decide to write a program to compute the final state of card stacks.
It’s partial judge for this problem.
Please download the code at the bottom to see the interface and main function.
You have to implement a data structure like below:
Input
Two integer N,M on the first line.
For each of the next N lines, there’re several integers Ni and Ci,1,Ci,2...Ci,Ni.
Ni means the number of cards in the i-th stack.
Ci,j denotes the j-th card of i-th stack.
The folloing M lines contains one action per line.
Every Action is one of “Merge x y” or “Cut x i”.
It’s guaranteed that:
- 1 ≤ N, M ≤ 9000
- ∑ Ni ≤ 4∗104
- Ci,j is non-negative integer.
- In “Merge x y” action:
- the x, y-th stacks always exist.
- x is not equal to y.
- In “Cut x i” action:
- the x-th stack always exists.
- i is always between 1 and Nx - 1.
- There’s at least 1 card in each card stack.
Output
Print the card stacks by the order of index.
One line for one card stack.
Please refer to the sample input/output for the precise format.
There is a ‘\n’ at the end of each line.
Sample Input Download
Sample Output Download
Partial Judge Code
12680.cPartial Judge Header
12680.hTags
Discuss
Description
After catching Jerryfish, Spongebob and Patrick thought they were happy enough so they went home. And then they found that Squidward had come home already :)
Squidward told them he need to drum up a marching band fast(for some reason). So he needed their help. Hence Spongebob and Patrick joined Squidward's band.
Today is their practicing day. Squidward is teaching all the members how to move at a performance. At a performance there are N rows. And in the i-th row, there are szi people. Note row may be empty(i.e. szi = 0). Everyone plays exactly one musical instrument. The musical instrument played by the j-th people in the i-th row is represented by a lower case letter cij.
Squidward ask them to move Q times. In each move, there are three types of moving:
- all the people in the ai-th row move to the front of the bi-th row (without messing up the original order)
- all the people in the ai-th row move to the back of the bi-th row (without messing up the original order)
- exchange all the people in the ai-th row and the bi-th row (without messing up the original order)
Now it’s your turn! You need to help them to move and tell Squidward the final formation in the end.
Input
The first line contains one integer N (1 ≤ N ≤ 105) – the number of rows.
Then N lines follow. First the i+1-th line contains one integer szi – the number of people in the i-th row. If there are some people in the row, a space character and szi characters cij are followed where cij is the musical instrument played by the j-th people in the i-th row. The sum of all the szi is less than or equal to 106.
The N+2-th line contains one integer Q (1 ≤ Q ≤ 105) – the times they need to move.
Then Q lines follow. The i+N+3-th line contains three integer typei, ai, bi (1 ≤ typei ≤ 3, 1 ≤ ai, bi ≤ N, ai ≠ bi) – the type of moving and the numbers of two rows which need to move.
It's guaranteed that:
- The 1st testcase must be identical to the Sample below
- For the first five testcases: 1 ≤ N, Q ≤ 103, the sum of all the szi ≤ 104
Output
After all the moving, for each row output all the musical instrument played in that row and then print a newline('\n') character.
If there is no people in some row, just output an empty line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Receiving lucky money is the favorite activity of children during Chinese New Year.
Denny's family has N children, everyone wants to get the lucky money as soon as possible.
The elders in the family have prepared a game to decide the order of receiving the lucky money:
- At the beginning, all children line up from left to right and numbered sequentially
- Randomly decide two number A and K, move the child at position A to the right by K positions, If he can't move K positions to the right, move to the far right.
For example:
N = 6, The initial order: 1 2 3 4 5 6
A = 3, K = 2, The new order: 1 2 4 5 3 6
A = 1, K = 3, The new order: 2 4 5 1 3 6
A = 5, K = 3, The new order: 2 4 5 1 6 3
Input
The first line contains two integer N M, the number of children and the number of times of changing positions
Each of he following M line contains two integer A K.
test cases:
(6/6) 1 <= A <= N, M, K <= 100
Output
The output contains N + 1 lines, the initial order and new order after changing position.