Ultraviolet A 11988 broken keyboard (Linked List Application)

Source: Internet
Author: User

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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.