题意:

模拟一个文本编辑器,可以输入字母数字下划线,如果遇到'['则认为是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)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988)

    破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988) 题意描述 你在输入文章的时候,键盘上的Home键和End键出了问题,会不定时的按下. ...

  4. 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:% ...

  5. 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 ...

  6. UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)

    题目代号:UVA 11988 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&pa ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. mysql 查看 索引

    查看索引 mysql> show index from tblname; mysql> show keys from tblname; · Table 表的名称. · Non_unique ...

  2. AssetBundle机制相关资料收集

    原地址:http://www.cnblogs.com/realtimepixels/p/3652075.html AssetBundle机制相关资料收集 最近网友通过网站搜索Unity3D在手机及其他 ...

  3. uva12534 Binary Matrix 2(最小费用最大流)

    http://blog.csdn.net/qq564690377/article/details/17082055 做的时候觉得明显是费用流,但是真的不知道怎么建图,看了上面的博客会稍微清晰一点.后面 ...

  4. call by reference and copy/restore

    转自:http://stackoverflow.com/questions/8848402/whats-the-difference-between-call-by-reference-and-cop ...

  5. cf 403 D

    D. Beautiful Pairs of Numbers time limit per test 3 seconds memory limit per test 256 megabytes inpu ...

  6. Linux的别名使用

    直接定义别名 编辑当前用户下的.bashrc 文件: vim  ~/.bashrc 添加别名为 lmysql 的命令语句 : alias lmysql='mysql -uroot -p -Dtest ...

  7. C#中对象的输出

    假设有个Costmer类如下: class Costmer { public string Id { get; set; } public string City { get; set; } publ ...

  8. HBase使用场景和成功案例

    1 典型互联网搜索问题:BigTable发明的原因 搜索使用场景 1) 爬虫持续不断地抓取新页面,这些页面每页一行地存储到HBase里. 2 )MapReduce计算作业运行在整张表上,生成索引,为网 ...

  9. mysql集群

    http://blog.chinaunix.net/uid-20586655-id-291471.html

  10. iOS开发--Bison详解连连支付集成简书

    "最近由于公司项目需要集成连连支付,文档写的不是很清楚,遇到了一些坑,因此记录一下,希望能帮到有需要的人." 前面简单的集成没有遇到什么坑,在此整理一下官方的集成文档,具体步骤如下 ...