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 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).

Output

For each case, print the Beiju text on the screen.

Sample Input

This_is_a_[Beiju]_text

[[]][][]Happy_Birthday_to_Tsinghua_University

Sample Output

BeijuThis_is_a__text

Happy_Birthday_to_Tsinghua_University

 

//超时代码

用两条链表。head存储排好序的,l_head另一条存储前面的,碰到']'和'\n'就连接起来,然后输出,可惜这超时了。可能用链表在创建时和删除时会很慢吧。但是为了纪念一下我的劳动。还是保存一下

 #include <iostream>
#include <cstring>
#include <deque>
using namespace std; struct num
{
char x;
struct num*next;
}; struct num *head;
struct num *endy;
struct num *cur,*ne; void sv_head()
{
if (cur!=NULL)
{
ne->next=head;
head=cur;
cur=NULL;
}
} int main()
{
int flag=;
char k;
head=NULL;
cur=ne=head;
while(k=getchar())
{
if (k!='\n')
{
if(k=='['){flag=;cur=NULL;continue;}
if(k==']'){flag=;sv_head();continue;}
if(flag)
{
if (head==NULL)
{
head=new num;
head->x=k;
head->next=NULL;
endy=head;
}
else
{
ne=new num;
ne->x=k;
ne->next=NULL;
endy->next=ne;
endy=ne;
}
}
else
{
if (cur==NULL)
{
cur=new num;
cur->x=k;
cur->next=NULL;
ne=cur;
}
else
{
ne->next=new num;
ne->next->x=k;
ne->next->next=NULL;
ne=ne->next;
}
}
}
else
{
sv_head();
cur=ne=head;
while (ne!=NULL)
{
printf("%c",ne->x);
ne=ne->next;
delete cur;
cur=ne;
}
printf("\n"); flag=;
head=NULL;
cur=ne=endy=NULL;
} }
return ;
}

//AC的 DFS 先输出后面括号里的

 #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std; char buf[];
void dfs(int l, int r)
{
int s = r;
while (s >= l && buf[s] != '[' && buf[s] != ']') s --;
if (buf[s] == ']') dfs(l, s-);
for (int i = s+ ; i <= r ; ++ i)
printf("%c",buf[i]);
if (buf[s] == '[') dfs(l, s-);
} int main()
{
while (gets(buf))
{
dfs(, strlen(buf)-);
printf("\n");
}
return ;
}

N - Broken Keyboard (a.k.a. Beiju Text)(DFS,链表)的更多相关文章

  1. 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 i ...

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

    题目代号:UVA 11988 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&pa ...

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

    题目大意:将一个字符串改变顺序后输出.遇到“[”就将后面内容拿到最前面输出,遇到“]”就将后面的内容拿到最后面输出. 题目分析:用nxt[i]数组表示i后面的字符的下标,实际上就是以字符i为头建立链表 ...

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

    使用list来模拟就行了,如果熟悉list,那么这道题真是分分钟秒掉... list是双向循环链表,插入和删除操作非常快,缺点是不能像数组一样随机按下标读取. 一下是wiki上说明的相关函数:http ...

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

  6. 破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988)

    破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988) 题意描述 你在输入文章的时候,键盘上的Home键和End键出了问题,会不定时的按下. ...

  7. UVA——11988 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 ...

  8. 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 ...

  9. 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 wi ...

随机推荐

  1. Charles的HTTPS抓包方法及原理,下载安装ssl/https证书

    转自:https://zhubangbang.com/charles-https-packet-capture-method-and-principle.html 本文的Charles,适应windo ...

  2. css - inline\inline-block\block

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. .net错误处理机制

    原地址:http://blog.csdn.net/lxbg90058/article/details/5651767 没有不出错的软件 从不出错的软件从某种程度上讲是不可能的! 和普通人的观念相反,创 ...

  4. windows盘符操作

    subst subst x: /d subst y: e:\

  5. Objective-C(十七、KVC键值编码及实例说明)——iOS开发基础

    结合之前的学习笔记以及參考<Objective-C编程全解(第三版)>,对Objective-C知识点进行梳理总结.知识点一直在变,仅仅是作为參考,以苹果官方文档为准~ 十七.键值编码 K ...

  6. 剑指Offer-正则表达式匹配(Python)

    1 题干内容 请实现一个函数用来匹配包括.和*的正则表达式.模式中的字符.表示任意一个字符,而*表示它前面的字符可以出现任意次(包含0次). 在本题中,匹配是指字符串的所有字符匹配整个模式. 例如,字 ...

  7. Jenkins集成Docker实现镜像构建和线上发布

    原文地址:http://www.cnblogs.com/keithtt/p/6410229.html 大概过程如下图: 由于需要用到docker打包镜像,jenkins宿主机上需要安装docker,原 ...

  8. node.js 学习03

    node.js学习03 解决浏览器接收服务端信息之后乱码的问题: 服务器通过设置http响应报文头,告诉浏览器使用相应的编码 来解析网页. res.setHeader('Content','text/ ...

  9. RabbitMQ消息队基本概念

    RabbitMQ简介 AMQP,即Advanced Message Queuing Protocol,高级消息队列协议,是应用层协议的一个开放标准,为面向消息的中间件设计.消息中间件主要用于组件之间的 ...

  10. MySQL(8)--Cluster 7.4 rpm centos7

    还没来得及写.我就知道一个月完毕不了,暂时添加的工作总是拖后腿. .. MySQL集群 docker下安装MySQL Cluster报错了.是我image的包少了perl.老实装吧.image又小不了 ...