N - Broken Keyboard (a.k.a. Beiju Text)(DFS,链表)
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,链表)的更多相关文章
- 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 ...
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)
题目代号:UVA 11988 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&pa ...
- UVA-11988 Broken Keyboard (a.k.a. Beiju Text) (链表 或 递归)
题目大意:将一个字符串改变顺序后输出.遇到“[”就将后面内容拿到最前面输出,遇到“]”就将后面的内容拿到最后面输出. 题目分析:用nxt[i]数组表示i后面的字符的下标,实际上就是以字符i为头建立链表 ...
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text) (链表,模拟)
使用list来模拟就行了,如果熟悉list,那么这道题真是分分钟秒掉... list是双向循环链表,插入和删除操作非常快,缺点是不能像数组一样随机按下标读取. 一下是wiki上说明的相关函数:http ...
- 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 ...
- 破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988)
破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988) 题意描述 你在输入文章的时候,键盘上的Home键和End键出了问题,会不定时的按下. ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- vue - 认识ora
主要用来实现node.js命令行环境的loading效果,和显示各种状态的图标等... const ora = require('ora'); const spinner = ora('Loading ...
- Linux启动U盘制作
Linux目前最好的u盘启动工具之一,下面介绍它的用法,首先下载Linux live OK了,一步一步跟我步骤走! 启动时,选择需要用的U盘 步骤二,就选择安装源即可(一般为ISO文件) 最后进行步骤 ...
- selenium从入门到应用 - 7,testNG的DataProvider
本系列所有代码 https://github.com/zhangting85/simpleWebtest 本文将介绍一个Java+TestNG+Maven+Selenium的web自动化测试脚本环境下 ...
- 【Python 数据分析】Numpy模块
Numpy模块可以高效的处理数据,提供数组支持.很多模块都依赖他,比如:pandas.scipy.matplotlib 安装Numpy 首先到网站:https://www.lfd.uci.edu/~g ...
- jQuery 文档操作 - prependTo() ,appendTo()方法
其他jquery文档操作方法:http://www.w3school.com.cn/jquery/jquery_ref_manipulation.asp jQuery 参考手册 - 文档操作 appe ...
- MongoDB密码设置(基于windows)
参考文档:http://www.cnblogs.com/zengen/archive/2011/04/23/2025722.html MongoDB部署到Windows上后是默认是无权限限制的的. ...
- Docker 安装docker-compose多容器管理服务
原文地址:https://github.com/eacdy/spring-cloud-book/blob/master/3%20%E4%BD%BF%E7%94%A8Docker%E6%9E%84%E5 ...
- TCP/IP ---互联网的地址
互联网上的每个接口必须有一个唯一的I n t e r n e t地址(也称作I P地址). I P地址长32 bit.I P地址具有一定的结构,五类不同 的互联网地址格式如图1 - 5所示. 这些3 ...
- 哈希—— POJ 3349 Snowflake Snow Snowflakes
相应POJ题目:点击打开链接 Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions ...
- 采用CDN加速后,如何在程序里获取用户IP地址
现在很多网站用了CDN技术,但采用CDN技术后,原来用来获取访问源的IP地址的程序已不能正常使用,它拿到的并不是访问源的真实IP地址,而是CDN节点的IP地址,解决方法是对获取IP的代码作一点小改动. ...