题目链接:https://vjudge.net/problem/UVA-11988

题目大意:输入一个字符串,输出在原本应该是怎么样的?  具体方法是 碰到' [ ' 回到最前面  碰到‘ ]’  回到最后面。

思路:很容易可以想到用数组来写,但是仔细分析一下,每次你把一个字符插入到最前面,它后面的字符全都要往后移,那么复杂度是多大呢?  最差的情况,每一个都插在最前面,呢么复杂度是

n*n   肯定超时的。  应用链表则只有n的复杂度了。  这是我接触到的第一道链表题目,说的详细一点:

比如   abcde    如果你要在ab  之间插入f   那么你首先把f的后继改为a的后继,a的后继改为f  这就插入完成了   其实这就是核心了。  但是为了方便  我们通常设置一个头结点  [0]   从1开始存数据:

下面看代码:

#include<iostream>
#include<string.h>
#include<vector>
#include<stdio.h>
using namespace std;
const int maxn=1e5+;
int main()
{
char a[maxn];
int next[maxn];
while(scanf("%s",a+)!=EOF)//存在s[1] s[2]~~~~中
{
int len=strlen(a+);//保存在s[1] s[2]~~~~中
int cur=;//光标在的位置 下次插入在光标所在位置后面一位
int last=;//最后一位所在的位置
next[]=;//初始化
for(int i=;i<=len;i++)//遍历一遍
{
char c=a[i];
if(c=='[') cur=;//光标调到最前面
else if(c==']') 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",a[i]);//按照链表输出
printf("\n");
}
return ;
}

Broken Keyboard (a.k.a. Beiju Text) UVA - 11988 (链表)的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. Person.post请求------详细过程

    首先,在PersonRepository的父类中查找save方法,如下: @Override @TransactionalMethod public <S extends D> S sav ...

  2. GitHub Pages搭建博客HelloWorld版

    1.原理 GitHub作为博客相关文件的托管方,你把按照jekyll规定的目录及文件上传至github库中,通过约定的库名称即可访问到经过jekyll渲染后的博客页面. 2.搭建过程 2.1.注册Gi ...

  3. web 后台打印

    //提交打印 function sbumitPrint() { printHidden("AppsDSPrintDoub.aspx?type=print"); } function ...

  4. ArcGIS Server GP服务使用常见错误总结

    ArcGIS GP服务问题列表 输入参数错误 在使用GP服务时,从创建模型到发布服务,再到调用服务,整个过程都需要注意输入参数和输出参数的问题.GP服务支持的输入和输出参数可详见 http://hel ...

  5. ASPxGridView KeyFieldName

    KeyFieldName="查询表的主键名称"

  6. [A/C 2007] 数据备份(网络流,堆)

    [A/C 2007] 数据备份(网络流,堆) 给你N各点的位置和K条链,需要用这些链把2K个点连起来,使得链的总长最短.可以随意选择要链的点.n=100000. 这道题居然可以用堆-- 首先,不能把区 ...

  7. 最优的cuda线程配置

    1 每个SM上面失少要有192个激活线程,寄存器写后读的数据依赖才能被掩盖   2 将 寄存器 的bank冲突降到最低,应尽量使每个block含有的线程数是64的倍数   3 block的数量应设置得 ...

  8. kuangbin专题十六 KMP&&扩展KMP HDU2594 Simpsons’ Hidden Talents

    Homer: Marge, I just figured out a way to discover some of the talents we weren’t aware we had. Marg ...

  9. ssm中实现excle导入导出

    1 pom.xml <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-oox ...

  10. git学习中遇到的疑难杂症

    GIT仓库如何恢复到前一次提交 一.通过使用Git版本恢复命令reset,可以回退版本 reset命令有3种方式: 1.git   reset   –mixed:此为默认方式,不带任何参数的git r ...