uva11988

maksyuki 发表于 oj 分类,标签:
0

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 5MB.

Output

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

Sample Input

This_is_a_[Beiju]_text

[[]][][]Happy_Birthday_to_Tsinghua_University

Sample Input

BeijuThis_is_a__text

Happy_Birthday_to_Tsinghua_University

 

题目类型:单向循环链表

算法分析:将字符串一行读入,逐个判断字符,如果字符是’[’,就将当前位置指针置为0,如果字符是’]’,就将当前位置指针置为尾指针指向的位置。如果字符是其他字符,就将该字符插入到当前指针所指向的字符位置的后一个,并更新当前指针,如果插入的位置是最后一个位置,则更新尾指针