Broken Keyboard (a.k.a. Beiju Text)

来源:互联网 发布:算法类的书籍推荐 编辑:程序博客网 时间:2024/05/29 10:35
点击打开链接

O - datastruct-easy
Crawling in process...Crawling failedTime Limit:1000MS    Memory Limit:0KB     64bit IO Format:%lld & %llu
SubmitStatus

Description

Problem B

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 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 5MB.

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

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<stdio.h>#include<string.h>char s[100008],z[100008];int main(){    while(scanf("%s",s)!=EOF)    {        int len=strlen(s),i,j;        for(i=0;i<len;i++)        {            if(s[i]=='['||s[i]==']')            z[i]='\0';            else z[i]=s[i];        }        z[len]='\0';        for(j=len-1;j>=0;j--)        {            if(s[j]=='[')            printf("%s",z+j+1);        }        if(!(s[0]=='['||s[0]==']'))        printf("%s",z);        for(j=0;j<len;j++)        {            if(s[j]==']')            printf("%s",z+j+1);        }        printf("\n");    }    return 0;}



原创粉丝点击