11988-broken Keyboard (a.k.a. Beiju Text)

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 are that sometimes the "home" key or the "end" key gets automatically pressed (internall Y).

You ' re not aware of this issue, since your ' re focusing on the text and do not even turn on the monitor! After your finished typing, you can see a text in 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 is several test cases. Each test case was a single line containing at least one and at the most 100,000
Letters, underscores and 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).

Output

For each case, print the Beiju text in the screen.

Sample Input

This_is_a_[beiju]_text
[[]][][]happy_birthday_to_tsinghua_university

Sample Output

Beijuthis_is_a__text
Happy_birthday_to_tsinghua_university

You have a broken keyboard. All keys on the keyboard work correctly, but sometimes the home or end keys are automatically pressed. You don't know that the keyboard is a problem, but rather focus on the script, not even the display is open. When you turn on the monitor, it is a tragic text that unfolds in front of you. Your task is to calculate the tragic text before opening the display.

The input contains multiple sets of data. One row for each group of data, containing no more than 100,000 letters, underscores, characters "[" or "]". where the character "[" means the Home key, "]" means the end key. The input end flag is the file Terminator (EOF). The input file does not exceed 5MB. For each set of data, the output line, the tragic text on the screen.
Sample input:

This_is_a_[beiju]_text
[[]][][]happy_birthday_to_tsinghua_university

Sample output:

Beijuthis_is_a__text
Happy_birthday_to_tsinghua_university

#include <cstdio>#include <string>#include <iostream>using namespace STD;structnode{CharC Node *next;}; Node *head; Node *tail; Node *p;intMain () {stringWords while(Cin>> words) {//Initialize the head node pointerHead =NewNode;//Head node next field emptyHead->next = NULL;//Initialize tail node pointertail = head;//Initialize auxiliary insert node pointerp = head; for(inti =0; I < words.length (); i++) {//Get a word            Charc = Words[i];//Home key            if(c = =' [') {//re-insert from headp = head; }Else if(c = ='] ') {//End key                //re-insert from tailp = tail; }Else{//Insert the word                //using the tail interpolation methodNode *n =NewNode; N->c = C;the next node of the insertion node is the next junction of the auxiliary node.N->next = p->next;//Auxiliary node the next node is an insertion node .P->next = n;//Auxiliary node pointer pointing to insertion nodep = n;//Auxiliary node the next node is the next node of the insertion node .                ///This means that the secondary node points to the insertion node, but the next node of the secondary node is still the node that has not been added to the insertion node .P->next = n->next;//tail pointer always points to tail                //The tail pointer moves backwards only after the end key is entered                if(P->next = = NULL)                {tail = p; }            }        }//Traversal outputp = Head->next; while(P! = NULL) {cout<< p->c;        p = p->next; }printf("\ n"); }return 0;}

11988-broken Keyboard (a.k.a. Beiju Text)

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.