11988-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
(internally).
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
Problem: Linked list, good question, code good hanging, looked at half a day, the more you see the feeling of hanging;
Code:
#include <iostream> #include <cstring> #include <cmath> #include <cstdio> #include < algorithm>using namespace Std;const int maxn=1e5+100;int En,cur,next[maxn];char s[maxn];int main () {while (~scanf ("% S ", s+1)) {int Len=strlen (s+1); cur=en=0;next[0]=0;for (int i=1;i<=len;i++) {if (s[i]== ' [') Cur=0;else if (s[i]== '] ') Cur=en;else{next[i]=next[cur];next[cur]=i;if (cur==en) en=i;cur=i;}} for (int i=next[0];i!=0;i=next[i]) printf ("%c", S[i]);p UTS ("");} return 0;}
Uva-broken Keyboard (a.k.a. Beiju Text) (linked list)