UV 11988 broken keyboard (simulated linked list)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.