See a freshman exercises, water before bedtime ~ ~ ~
Problem Bbroken 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 character S ' [' 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 in the screen.
Sample Input
This_is_a_[beiju]_text[[]][][]happy_birthday_to_tsinghua_university
Output for the Sample Input
Beijuthis_is_a__texthappy_birthday_to_tsinghua_university
Rujia Liu ' s Present 3: A Data Structure Contest celebrating the 100th anniversary of Tsinghua University
Special thanks:yiming Li
Note:please Make sure to test your program with the gift I/O files before submitting!
#include <iostream> #include <stdio.h> #include <string> #include <cstring> #include < Algorithm> #define N 100009using namespace Std;char s[n];int next[n];//What is the number after the ~int main () { while (~scanf ("%s", s+1)) { next[0]=0; int cur=0,la=0; int Len=strlen (s+1); for (int i=1;i<=len;i++) { char c=s[i]; if (c== ' [') cur=0; else if (c== '] ') Cur=la; else { next[i]=next[cur]; next[cur]=i; if (la==cur) la=i; cur=i; } } int i; for (I=next[0];i!=0;i=next[i]) printf ("%c", S[i]); cout<<endl; } return 0;}
UVA11988 Broken Keyboard (a.k.a. Beiju Text)