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. 【C/C++学院】0831-类与对象的异常/面试100题1-100

    类与对象的异常 Cpp异常 #include <iostream> #include <string.h> using namespace std; //标识错误的类型 cla ...

  2. GBDT--简单理解

    梳理 1.Model Ensemble 能够分为三大类:Bagging,Boosting. Stacking. 2.Boosting能够说是一个思想(框架),而Adaboost等算法仅仅是其一个子类, ...

  3. Ubuntu——修正LibreOffice中文乱码以及eclipse提示框颜色

    刚进ubuntu的时候就老遇到用libreoffice打开某些文档时出现一堆叠在一起的乱码.以及最開始使用eclipse编辑时,鼠标放到一个变量或者函数时 弹出来一黑框框-看的难受的.... 这里记录 ...

  4. unsupported major.minor version 解决方法

        转载自http://hi.baidu.com/fatchong/blog/item/191da23b478bbfef15cecbae.html         一直以来都是用jdk1.5,这次 ...

  5. Loadrunner11之VuGen常用函数lr_user_data_point(一)

    Loadrunner11之VuGen常用函数lr_user_data_point(一) 上一篇 / 下一篇  2011-11-15 00:15:33 / 精华(1) / 置顶(1) / 个人分类:性能 ...

  6. 使用 Visual Studio 2012进行C语言开发

    1.打开visual studio,选择菜单[文件]->[新建]->[项目],将会弹出新建项目对话框 2.在弹出的新建项目对话框中,选择和填补相应的属性. 3.点击确定之后,会跟着弹出应用 ...

  7. 使用svn hooks 脚本post-commit时遇到的故障

    由于网站上线,需要把新添加功能上传到测试环境进行测试,但由于程序员每天有大量的修改,如果总是登陆服务器手动更新svn工作副本(测试环境)太耗时耗精力,进而增加svn进行commit时,测试环境即时更新 ...

  8. radiusd cisco限速问题

    http://puck.nether.net/pipermail/cisco-bba/2011-February/001349.html

  9. pandas 绘图与滑窗

    #import nessary library before start import pandas as pd import numpy as np import matplotlib.pyplot ...

  10. Autofc与Mvc,WebForm,Weiapi,Owin整合源码分析

    主要分析一下的几个项目: Autofac.Integration.Mvc Autofac.Integration.WebApi Autofac.Integration.Owin Autofac.Int ...