If a keyboard breaks down and you do not know it, press home or end to give you the actual input of the keyboard. The actual display on the display is displayed.
The input is up to 5 MB, so direct array retrieval will definitely time out and use an array to simulate the linked list.
#include<cstdio>#include<cstring>using namespace std;const int N=100005;char s[N];int next[N];int main(){ int last,cur; while(~scanf("%s",s+1)) { next[0]=last=cur=0; int length=strlen(s+1); for(int i=1;i<=length;++i) { if(s[i]=='[') cur=0; else if(s[i]==']') cur=last; else { next[i]=next[cur]; next[cur]=i; if(cur==last) last=i; cur=i; } } for(int i=next[0];i;i=next[i]) printf("%c",s[i]); printf("\n"); } return 0;}
Broken keyboard
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_Tsinghua_University
Output for the sample input
BeijuThis_is_a__textHappy_Birthday_to_Tsinghua_University
UV 11988 broken keyboard (simulated linked list)