【codevs 4650】破损的键盘

来源:互联网 发布:入侵网站软件 编辑:程序博客网 时间:2024/04/29 00:43

4650 破损的键盘
时间限制: 1 s
空间限制: 16000 KB
题目等级 : 黄金 Gold
题解
题目描述 Description
有一天,你需要打一份文件,但是你的键盘坏了,上面的”home”键和”end”键会时不时地按下,而你却毫不知情,甚至你都懒得打开显示器,当你打开显示器之后,出现在你的面前的是一段悲剧的文本。

输入描述 Input Description
输入只有一行,即这份文件,这份文件只包含小写字母和’[‘以及’]’,用’[‘代替”home”键,用’]’代替”end”键。

输出描述 Output Description
你的任务是在打开显示器之前,计算出这份悲剧的文档。

样例输入 Sample Input
kdg[gek]h[itj

de[co]vs

样例输出 Sample Output
itjgekkdgh

codevs

数据范围及提示 Data Size & Hint
包含多组测试数据,直到文件结束。

字符串长度小于10000个字符。

不包含空格。

链表
下标与next的跳跃

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 100005;int now,tail,next[MAXN];//下标 尾 链表char s[MAXN];void init(){    memset(next,0,sizeof(next));    now = 0,tail = 0;    return;}int main(){    while(scanf("%s",s + 1) == 1)    {        int n = strlen(s + 1);        init();        for(int i = 1; i <= n; i ++)        {            if(s[i] == '[') now = 0;            else if(s[i] == ']')    now = tail;            else            {                next[i] = next[now];                next[now] = i;                if(tail == now) tail = i;                now = i;            }        }        for(int i = next[0]; i != 0; i = next[i])            printf("%c",s[i]);        puts("");    }    return 0;}
1 0
原创粉丝点击