Broken keyboard (a.k. A. beiju text)
You're typing a long text with a broken keyboard. well it's not so badly broken. the only problem with the keyboard is that sometimes the "home" key or the "end" Key gets automatically pressed (Internally ).
You're not aware of this issue, since you're focusing on the text and did not even turn on the monitor! After you finished typing, you can see a text on the screen (if you turn on the monitor ).
In Chinese, we can call it beiju. Your task is to find the beiju text.
Input
There are several test cases. each test case is a single line containing at least one and at most 100,000 letters, underscores and two special characters '[' and ']'. '['means the "home" Key is pressed internally, and'] 'means the "end" Key is pressed internally. the input is terminated by end-of-file (EOF ). the size of input file does not exceed 5 MB.
Output
For each case, print the beiju text on the screen.
Sample Input
This_is_a _ [beiju] _ text [[] [] [] [] happy_birthday_to_tsing1__university
Output for the sample input
Beijuthis_is_a _ texthappy_birthday_to_tsing1__university
The Home Key and end key of the computer keyboard are automatically pressed when you do not pay attention to them.
Here is an input sequence '[' indicates the Home Key ']', which indicates that the end key requires the corresponding output on the output screen.
Use a linked list to save the character C at each position and the serial number next at the next position. The next of the last character is 0.
Use cur to indicate the movement of the cursor
# Include <cstdio> # include <cstring> using namespace STD; const int n = 100005; char s [N], C; int cur, last, l; struct node {char C; int next;} Lis [N]; int main () {While (~ Scanf ("% s", S + 1) {L = strlen (S + 1); Lis [0]. next = last = cur = 0; For (INT I = 1; I <= L; ++ I) {c = s [I]; if (C = '[') cur = 0; else if (C = ']') cur = last; else {Lis [I]. C = C; Lis [I]. next = Lis [cur]. next; Lis [cur]. next = I; If (cur = last) Last = I; cur = I ;}} for (INT I = Lis [0]. next; I! = 0; I = Lis [I]. Next) printf ("% C", Lis [I]. c); printf ("\ n") ;}return 0 ;}