/*数组形式描述链表:链表不一定要用指针。
题目链接:UVa 11988 Broken Keyboard
题目大意:
小明没有开屏幕输入一个字符串,电脑键盘出现了问题会不定时的录入 home end 两个键,
我们知道如果录入home则将光标定位到字符首,如果录入end则是将光标定位到字符尾。现
在让你输出这段坏了文本。 表示:home => '[' , end => ']'
举例:
input: hello[_Tom_]!
output: _Tom_hello!
解题思路:
数组中频繁移动元素是很低效的,如有可能,可以使用链表。 */
#include<bits/stdc++.h>
using namespace std;
const int maxn=+;
int last,cur,next[maxn];
char s[maxn];
int main()
{
while(scanf("%s",s+)==) {
int n=strlen(s+);
last=cur=;
next[] = ;
for(int i=; i<=n; i++) {
char ch=s[i];
if(ch=='[')cur=;
else if(ch==']')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]);
printf("\n");
}
return ;
}

UVa 11988 Broken Keyboard(链表->数组实现)的更多相关文章

  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 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)

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

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

  4. UVa 11988 Broken Keyboard(数组模拟链表)

    题目链接: https://cn.vjudge.net/problem/UVA-11988 /* 问题 将一段文本经过一定的规则处理后输出,规则就是[表示home键,表示光标跳到行首,]表示end键, ...

  5. Uva 11988 Broken Keyboard STL+链表

    两种方法,直接上代码 STL标准模板库 #include <iostream> #include <list> #include <algorithm> #incl ...

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

    题目传送门 题意:训练指南P244 分析:链表模拟,维护链表的head和tail指针 #include <bits/stdc++.h> using namespace std; const ...

  7. UVA 11988 Broken Keyboard (a.k.a. Beiju Text) (链表,模拟)

    使用list来模拟就行了,如果熟悉list,那么这道题真是分分钟秒掉... list是双向循环链表,插入和删除操作非常快,缺点是不能像数组一样随机按下标读取. 一下是wiki上说明的相关函数:http ...

  8. UVA 11988 Broken Keyboard (链表)

    简单题,题目要求显然是很多次插入,所以是链表. 插入两个语句,nxt[i] = nxt[u] 表示 i结点指向u的后继, nxt[u] = i表示把u的后继设成i. 设置一个头结点,指向一个不存在的结 ...

  9. Uva 11988 Broken Keyboard

    因为要经常移动这些字符,所以采用的数据结构是链表. next[i]起到的作用大概就是类似链表里的next指针. 0.需要注意的是,判断cur == last ? 如果 是 则 last=i 1.另外一 ...

随机推荐

  1. fio 2种画图方法 fio_generate_plots 和 gfio

    fio 安装fio apt-get install fio 可以把fio的输出数据自动画图的插件gnuplot apt-get install gnuplot 1.输出bw,lat和iops数据并画图 ...

  2. Redis集群(五):集群搭建

    一.本文目的        演示在一台机器上搭建3主3从的redis集群,通过演示了解redis集群的搭建,使用和注意事项     二.搭建说明        1.同一台机器搭建3主3从的伪集群   ...

  3. Sublime Text插件:HTML+CSS+JAVASCRIPT+JSON快速格式化[转]

    今天在github上乱逛,无意间找到victorporof分享的htmlpretty插件,特做推荐: 先看看他是怎么描述htmlpretty的: This is a Sublime Text 2 an ...

  4. 100726C

    显而易见,我们要找子串,每次记录前缀和,算出余数,然后通过一个数组保存余数,答案就是加上之前余数的总和,要注意整除的情况 #include<iostream> #include<cs ...

  5. iis 发布静态 html 代码

    参考地址: http://jingyan.baidu.com/article/c843ea0b7d0b7177921e4a68.html 操作步骤:1.在当前发布网站中建立虚拟目录 2.点击当前网站 ...

  6. git 笔记1

    代码 kamil@ubuntu:~/github/xzdz$ git init Initialized empty Git repository in /home/kamil/github/xzdz/ ...

  7. 60.Android通用流行框架大全

    转载:https://segmentfault.com/a/1190000005073746 Android通用流行框架大全 1. 缓存 名称 描述 DiskLruCache Java实现基于LRU的 ...

  8. 【BZOJ-2527】Meteors 整体二分 + 树状数组

    2527: [Poi2011]Meteors Time Limit: 60 Sec  Memory Limit: 128 MBSubmit: 831  Solved: 306[Submit][Stat ...

  9. $(document).click() 在苹果手机上不能正常运行

    前几天,一位同事在微信上测试一个JQuery的写的购物车功能,出现了一个很奇怪的现象,在android系统上可以正常绑定,但是在iOS上确不能用,经过排除分析,发现其使用了jquery的$(docum ...

  10. Qt出现cannot find -IGL错误

    Solution: sudo apt-get install build-essential sudo apt-get install libgl1-mesa-dev