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

看到大一练习题,睡前水一水~~~

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__text
Happy_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 <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <algorithm>
#define N 100009
using namespace std;

char s[N];
int next[N];//存第i号后面是几号~

int main()
{
    while(~scanf("%s",s+1))
    {
        next[0]=0;
        int cur=0,la=0;
        int len=strlen(s+1);

        for(int i=1;i<=len;i++)
        {
            char c=s[i];

            if(c=='[')
            cur=0;
            else if(c==']')
            cur=la;
            else
            {
                next[i]=next[cur];
                next[cur]=i;
                if(la==cur) la=i;
                cur=i;
            }
        }

        int i;
        for(i=next[0];i!=0;i=next[i])
        printf("%c",s[i]);
        cout<<endl;

    }
    return 0;
}
时间: 2024-10-17 21:45:54

UVA11988 Broken Keyboard (a.k.a. Beiju Text)的相关文章

UVA11988 Broken Keyboard (a.k.a. Beiju Text)【数组模拟链表】

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 (inter

Uva11988 Broken Keyboard (a.k.a. Beiju Text)(就是先输出括号的字符)

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 automa

UVA-11988 Broken Keyboard (a.k.a. Beiju Text) (链表 或 递归)

题目大意:将一个字符串改变顺序后输出.遇到“[”就将后面内容拿到最前面输出,遇到“]”就将后面的内容拿到最后面输出. 题目分析:用nxt[i]数组表示i后面的字符的下标,实际上就是以字符i为头建立链表,写法类似链式前向星. 代码如下: # include<iostream> # include<cstdio> # include<cstring> # include<algorithm> using namespace std; char p[100005]

UVa11988 Broken Keyboard (a.k.a. Beiju Text) (链表)

链接:http://acm.hust.edu.cn/vjudge/problem/18693分析:链表.用nxt[i]保存s[i]右边字符在s中的下标.增加一个虚拟字符s[0],那么nxt[0]就是显示屏中最左边的字符.cur表示光标位置左边的字符在s数组中的下标,last表示显示屏中最后一个字符在s数组中的下标.其实就是用nxt链表重新组织s数组的输出顺序,输入一个字符,先将新插入字符的nxt[i]指向nxt[cur],再将nxt[cur]指向i,就是在链表元素cur后插入元素i,更新最后一个

【日常学习】【非指针链表】Uva11988 - Broken Keyboard (a.k.a. Beiju Text)题解

这道题目拖了好几天,因为鄙人有两大天敌--链表和树TUT看了这个题材知道原来链表可以不用指针写,不过原理也是一样的,相当于是用数组模拟了个链表而不实用结构体,结构体里的指针就换成了两个变量cur和last了.这道题目本来测出来非常奇怪和合因为UVA AC HDU TLE SPOJ RE我正在奇怪,才发现同名的不同题目有三道TUT 题目的详解已经写在了注释里,上代码: #include<cstdio> #include<cstring> using namespace std; co

uva - Broken Keyboard (a.k.a. Beiju Text)(链表)

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 problemwith the keyboard is that sometimes the “home” key or the “end” key gets automatically pressed(internally).Yo

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

N - Broken Keyboard (a.k.a. Beiju Text) Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description 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 som

Broken Keyboard (a.k.a. Beiju Text) UVA, 11988(链表)

Broken Keyboard (a.k.a. Beiju Text) From:UVA, 11988 Time Limit: 1000 MS 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 "hom

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

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 (inter