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 ...
随机推荐
- ZOJ2929 Penalty Kick(概率)
题目挺水的,但由于其独特的阅读量比赛的时候没发现这道水题,在此做一下翻译,如果有人搜到这翻译的话有帮助的话自然最好啦. 中国队平局进入最后的点球决胜局,首先抛硬币决定谁先罚球,然后先是罚五球,如果罚的 ...
- Android activity属性
android:allowTaskReparenting 是否允许activity更换从属的任务,比如从短信息任务 切换到浏览器任务. android:alwaysRetainTaskState 是否 ...
- 无线Ad-hoc网络的关键技术之路由(转)
无线Ad-hoc网络的关键技术之路由http://network.51cto.com/art/201003/189719.htm
- C 和C++ 名称修饰规则
C名称修饰规则 1.对于使用__cdecl调用约定的函数,在函数名称前加一下划线,不考虑参数和返回值. 2.对于使用__fastcall调用约定的函数,在函数名称前后各加一@符号,后跟参数的长度,不考 ...
- http://blog.csdn.net/luxiaoyu_sdc/article/details/7333024
http://blog.csdn.net/luxiaoyu_sdc/article/details/7333024 http://blog.csdn.net/kkdelta/article/detai ...
- 【转】SQL Server T-SQL写文本文件
原文:http://www.nigelrivett.net/SQLTsql/WriteTextFile.html The are several methods of creating text fi ...
- angularJS之$apply()方法
这几天,根据buddy指定的任务,要分享一点angular JS的东西.对于一个在前端属于纯新手的我来说,Javascript都还是一知半解,要想直接上手angular JS,遇到的阻力还真是不少.不 ...
- ActiveMQ和Tomcat的整合应用(转)
转自:http://topmanopensource.iteye.com/blog/1111321 ActiveMQ和Tomcat的整合应用 博客分类: ActiveMQ学习和研究 在Active ...
- 在linux/unix中查找大文件
在linux/unix中查找大文件,如查找大于100M文件的位置路径,查找等于10M文件的位置路径等等,下面就介绍几个实现快速查找的命令: 1. 查找指定目录下所有大于100M的文件,命令为 find ...
- QT静态编译
Qt静态编译(链接)和动态编译区别 Qt的静态编译译(其实应该叫链接,不是编译),将各模块编译成静态库,这样在编译自己写的Qt程序时,会将这些静态库编译(链接)到你的EXE文件中去的.Qt的动态编译, ...