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 ...
随机推荐
- 微信小程序 - bindcontroltap和control的关系(map)
听说最近要废弃control,用cover-image和cover-view替代它,层级问题(我们此等萌新们还在想图标怎么显示在地图上(-.-)) 粗略的来说,一个展示(control),一个触发(b ...
- Django——如何使用Template以及如何向template传递变量
如何使用模板系统 在Python代码中使用Django模板的最基本方式如下: 可以用原始的模板代码字符串创建一个 Template 对象, Django同样支持用指定模板文件路径的方式来创建 Temp ...
- git 基于某个分支创建分支
1.拷贝源代码 git clone git@git地址 cd 项目目录 2.根据已有分支创建新的分支 git checkout -b yourbranchname origin/oldbranchna ...
- 在Ubuntu 12.04上配置iSCSI Target服务
今天自己按照网上搜来的教程自己在Ubuntu 12.04上配置了iSCSI Target服务,在这里简单地做个纪录.操作系统是全新安装的Ubuntu 12.04,配置一块500 GB的SATA笔记 ...
- 说说C#的数学类,Math,浮点数(上)
说说C#的数学类,Math,浮点数 C#语言支持下图所看到的的数值类型,各自是整数,浮点数和小数 可能不是非常清楚,可是细致看看还是能看清楚的. 在一个C#程序中,整数(没有小数点的数)被觉得是一个i ...
- mysql调用存储过程出现Illegal mix of collations错误
执行sql语句正常 执行存储过程 异常 提示 Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMP ...
- c#中从string数组转换到int数组及比较两个字符串相等
string[] input = { "1", "2", "3", "4", "5", " ...
- Atitit.code base view 视图的实现原理
Atitit.code base view 视图的实现原理 1. 视图的执行算法:1 2. 不可更新的视图:1 3. 关于视图的可插入性:insert2 4. 视图定义3 5. 调用3 1. 视图的执 ...
- OA项目之权限设计②
1.接着昨天的今天到了设计怎样成功的实现权限分配的功能,首先我们看下这些功能的过程例如以下图: 首先是从user的list页面看到设置权限的button,点击进去进入设置权限的页面 进入设置权限页面, ...
- oracle数据库性能优化方案精髓整理收集回想
oracle数据库性能优化整体法则: 一.降低数据訪问(降低硬盘房訪问次数) 二.返回更少的数据(降低网络传输或磁盘訪问) 三.降低交互次数(降低网络传输) 四.降低server开销(降低cpu及内存 ...