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. 对象内部属性[[Class]]

    1.概述 所有的typeof返回值为‘object’的对象都包含一个内部属性[[Class]],我们将它可以看做内部的分类,而非传统面向对象意义的分类.这个属性无法直接访问,一般通过Object.pr ...

  2. 【Oracle】查找每期数据都存在的产品

    现在存在以下数据 如上图:A01与A02同时存在201710.201711.201712中 我们现在要将其查找出来 如果上图的表结构如下: 那么查询的SQL如下: SELECT DISTINCT CO ...

  3. <转> lua: userdata的metatable使用

    1 如何封装c++的指针 对于c++对象的lua包装,我们可以使用 template<typename T> struct luaUserdataWrapper {  luaUserdat ...

  4. Strategy模式

    Strategy模式 Strategy模式要解决的问题和Template模式类似.都是为了把算法的声明和算法的实现解耦.Template模式是通过继承来实现的,而Strategy模式是通过组合来实现的 ...

  5. iOS开发多线程篇 09 —NSOperation简单介绍

    iOS开发多线程篇—NSOperation简单介绍 一.NSOperation简介 1.简单说明 NSOperation的作⽤:配合使用NSOperation和NSOperationQueue也能实现 ...

  6. 2017-5-14 湘潭市赛 Parentheses 转化思想+贪心 使括号序列合法的最小花费。满足前面左括号的数量>=有括号的数量。

    Parentheses Accepted : Submit : Time Limit : MS Memory Limit : KB Parentheses Bobo has a very long s ...

  7. mysql的两个备份语句

    适合多引擎混合(例如:myisam与innodb混合)的备份命令如下: mysqldump -A -R --triggers --master-data=2 --single-transaction  ...

  8. 谈谈 epmd

    在<Erlang/OTP 并发编程实战>中,对 epmd 有如下描述: epmd  代表 Erlang 端口映射守护进程(Erlang Port Mapper Daemon). 每启动一个 ...

  9. 基于consul构建golang系统分布式服务发现机制

    原文地址-石匠的Blog: http://www.bugclosed.com/post/5 在分布式架构中,服务治理是一个重要的问题.在没有服务治理的分布式集群中,各个服务之间通过手工或者配置的方式进 ...

  10. Tensorflow如何选择GPU

    CUDA_VISIBLE_DEVICES=1 python run.py or import os os.environ["CUDA_VISIBLE_DEVICES"]=" ...