例题6-4 Broken Keyboard UVa11988

题目分析:

起初这道题目没有做出来,原因是我一直想把整块区域一并插入,而不是逐个插入。今后做题应该注意这个问题,把问题分解去考虑,也许会少走许多弯路。

下边附上AC代码

#include <cstdio>
#include <cstring>
#include <cctype>
char s[100000 + 10];
int next[100000 + 10];
int main(){
    while(scanf("%s", s + 1) == 1){
        int len=strlen(s+1);
        int cur = 0,last=0;
        next[0] = 0;
        for(int i = 1;i <= len;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 != 0;i = next[i]){
            printf("%c",s[i]);
        }
        printf("\n");

}
    return 0;
}
//

时间: 2024-10-22 10:43:45

例题6-4 Broken Keyboard UVa11988的相关文章

UVa11988 Broken Keyboard(悲剧文本)

UVa11988 Broken Keyboard(悲剧文本) 题目链接:UVa11988 题目描述: 输入包含多组数据,每组数据占一行,包含不超过100000个字母.下划线.字符"["或者"]".其中字符"["表示Home键,"]"表示End键.输入结束标志为文件结束符(EOF)输入文件不超过5MB,对于每组数据,输出一行,即屏幕上的悲剧文本 样例输入: This_is_a_[Beiju]_text [[]][]Happy_B

UVa11988:Broken Keyboard

Description Broken KeyboardYou'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 gets automatically pressed (internally). You're not aware of this iss

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

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 a

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

UVa11988-破损的键盘 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 thi

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

1084. Broken Keyboard (20)

On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen. Now given a string that you are supposed to type, and the string that you actually type out, p