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 ...
随机推荐
- 关于linux系统如何实现fork的研究(二)
本文为原创,转载请注明:http://www.cnblogs.com/tolimit/ 引言 前一篇关于linux系统如何实现fork的研究(一)通过代码已经说明了从用户态怎么通过软中断实现调用系统调 ...
- IOS 提交审核,遇到Missing Push Notification Entitlement 问题。
貌似不影响提交........还是有人提交成了. 昨天晚上提交软件审核,遇到了Missing Push Notification Entitlement 的问题. 问题起因:这个版本我添加了PUSH推 ...
- DirectShow 最简单的入门 -- 播放一段视频
#include <dshow.h> #pragma comment(lib,"strmbase.lib") #pragma comment(lib,"qua ...
- Google Chrome 浏览器禁用缓存
在使用 Google Chrome 浏览器调试 js 时,会发现修改完 js 不会立即生效,这是由于 chrome 浏览器缓存的原因,而在火狐下没有这个问题.经常使用 chrome 浏览器调试 js ...
- LSTM/RNN的应用Case
作者:许铁-巡洋舰科技链接:https://www.zhihu.com/question/37082800/answer/126430702来源:知乎著作权归作者所有,转载请联系作者获得授权. 作者: ...
- iOS多线程的初步研究(四)-- NSTimer
理解run loop后,才能彻底理解NSTimer的实现原理,也就是说NSTimer实际上依赖run loop实现的. 先看看NSTimer的两个常用方法: + (NSTimer *)timerWit ...
- Javascript nextElementSibling和nextSibling
function next(ele) { if (typeof ele.nextElementSibling == 'object') { return ele.nextElementSibling; ...
- (转)Android: NDK编程入门笔记
转自: http://www.cnblogs.com/hibraincol/archive/2011/05/30/2063847.html 为何要用到NDK? 概括来说主要分为以下几种情况: 1. 代 ...
- mysql 连接数的最大数
mysql默认最大连接数是100,增加加默认MYSQL连接数的方法有两个 方法一:进入MYSQL安装目录 打开MYSQL配置文件 my.ini(windows) 或 my.cnf(linux环境)查找 ...
- CF 353A Domino
#include<stdio.h> #include<math.h> int main() { int i,n; int x,y; int m1,m2,m3,m4; while ...