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 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
#include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <stack > #include <queue> #include <map> #include <set> #include <vector> #include <math.h># Include <bitset> #include <list> #include <algorithm> #include <climits>using namespace std;# Define Lson 2*i#define Rson 2*i+1#define LS l,mid,lson#define RS mid+1,r,rson#define Up (i,x,y) for (i=x;i<=y;i++) # Define down (i,x,y) for (i=x;i>=y;i--) #define MEM (a,x) memset (A,x,sizeof (a)) #define W (a) while (a) #define GCD (A, B) __ GCD (A, b) #define LL long long#define N 100005#define MOD 1000000007#define INF 0x3f3f3f3f#define EXP 1e-8#define lowbit (x) (x&-x) Char str[n];int next[n];int main () {int i,j,cur,last; while (gets (str+1)) {int len = strlen (str+1); cur = last = 0; Next[0] = 0; for (i = 1; i<=len; i++) {if (str[i]== ' [') cur = 0; else if (str[i]== '] ') cur = last;else {Next[i] = Next[cur]; Next[cur] = i; if (last = = cur) last = i; cur = i; }} for (i = next[0]; i; i = Next[i]) printf ("%c", Str[i]); Puts (""); } return 0;}
Uva11988:broken Keyboard (a.k.a. Beiju Text)