UVa 11988 (数组模拟链表) Broken Keyboard (a.k.a. Beiju Text)
题意:
模拟一个文本编辑器,可以输入字母数字下划线,如果遇到'['则认为是Home键,如果是']'则认作End键。
问最终屏幕上显示的结果是什么字符串。
分析:
如果在数组用大量的移动字符必然很耗时。所以next数组表示显示屏中s[i]右边的字符编号,变量cur模拟光标,即当前光标位于s[cur]的右边。
变量last记录显示屏最后一个字符的下标。
我理解的连接的情况应该是这样子的:

//#define LOCAL
#include <cstdio>
#include <cstring> const int maxn = + ;
int last, cur, next[maxn];
char s[maxn]; int main(void)
{
#ifdef LOCAL
freopen("11988in.txt", "r", stdin);
#endif while(scanf("%s", s + ) == )
{
int n = strlen(s + );
last = cur = ;
next[] = ; for(int i = ; i <= n; ++i)
{
char ch = s[i];
if(s[i] == '[') cur = ;
else if(s[i] == ']') cur = last;
else
{
next[i] = next[cur];
next[cur] = i;
if(cur == last) last = i; //更新最后一个字符编号
cur = i; //移动光标
}
} for(int i = next[]; i != ; i = next[i])
printf("%c", s[i]);
puts("");
} return ;
}
代码君
UVa 11988 (数组模拟链表) Broken Keyboard (a.k.a. Beiju Text)的更多相关文章
- 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 ...
- 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 ...
- 破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988)
破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988) 题意描述 你在输入文章的时候,键盘上的Home键和End键出了问题,会不定时的按下. ...
- 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:% ...
- 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 ...
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)
题目代号:UVA 11988 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&pa ...
- 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 ...
- UVa 11988 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 ...
- Broken Keyboard (a.k.a. Beiju Text) UVA - 11988
You're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem wi ...
随机推荐
- Ckeditor 的加载顺序
我们的只用在文件里面引用一个CKEditor的js文件--CKEditor目录下的ckeditor.js文件, 该文件会完成后续的所有的CKEidtor依赖的js文件的加载. 所依赖的js文件加载顺序 ...
- jquery json遍历和动态绑定事件
<div id='tmpselectorList' style='border: 1px solid grey;max-height: 150px;position:absolute;text- ...
- VMware 进入bios
在虚拟机创建目录中找到.vmx结尾的文件. 添加bios.forceSetupOnce = "TRUE". 打开虚拟机,他会自动进入bios,随后他会把bios.forceSetu ...
- hdu 1526(最大匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1526 思路:floyd求传递闭包,然后就是最大匹配了,不过一开始输入没看清,被坑了将近2个小时. #i ...
- nil和NULL
- 545B. Equidistant String
题目链接 输入两个只含有01的字符串,s,t 求一个字符串p使到s,t的距离一样 这里的距离是指对应位置:0-0的距离是0 ,o-1的距离是1 ,1-1的距离是0,1-0的距离是1 这里只要求找出满足 ...
- 转:Move all SQL Server system databases at one time
Problem One task that you may need to do as a DBA is to move the system databases from one location ...
- Mysql笔记——DCL
DCL数据库控制语言不同于程序设计语言,SQL语言(结构化查询语言)的组成部分包括了DCL数据库控制语言. =============== 1.创建用户 语法:CREATE USER 用户名@地址 ...
- [iOS]提交App报错ERROR ITMS -90207
前几天上传项目N多次,都跳出这个问题 甚是头痛,于是乎各种搜索 1. 第三方的info.plist里面Executable file这个要删除(自己的不能删哦) 2.检查一下用来做跳转到第三方应用的设 ...
- Oracle ->> ENABLE VALIDATE & DISABLE VALIDATE
这里找到一篇博文对这两个用法的解释:http://www.cnblogs.com/rootq/archive/2008/09/23/1297400.html 启用约束: enable( validat ...