两种方法,直接上代码

STL标准模板库

#include <iostream>
#include <list>
#include <algorithm>
#include <cstdio>
using namespace std;
const maxn=100000+5;
char str[maxn];
typedef list<char> L;
int main(){
while(gets(str)){
L l;
L::iterator p;
int len=strlen(str);
for(int i=0;i<len;i++){
if (str[i]=='[') p=l.begin();
else if(str[i]==']') p=l.end();
else l.insert(p,str[i]);
}
for(p=l.begin();p!=l.end();p++)
printf("%c",*p);
printf("\n");
}
return 0;
}

数组模拟链表

#include <cstdio>
#include <cstring>
const int maxn=100000+5;
int last,cur,next[maxn];//光标位于cur字号的后面
char s[maxn];
int main(){
while(scanf("%s",s+1)==1){
int n=strlen(s+1);//输入保存在s[1],s[2],s[3],后面
cur=last=0;
next[0]=0;//头节点指向空
/*
从1到n逐个遍历
*/
for (int i=1;i<=n;i++){
char ch=s[i];
if (ch=='[') cur=0;
else if (ch==']') cur=last;
//交换性伴侣
else {
next[i]=next[cur];//新来的结点插向gay2p的后者
next[cur]=i;//gay2p的前者插向新来的结点
if (cur==last) last=i;//更新"最后一个字符"的编号
cur=i;//改变搜索2p对
}
}
for(int i=next[0];i!=0;i=next[i])
printf("%c",s[i]);
printf("\n");
}
return 0;
}

  

Uva 11988 Broken Keyboard STL+链表的更多相关文章

  1. UVa 11988 Broken Keyboard(链表->数组实现)

    /*数组形式描述链表:链表不一定要用指针. 题目链接:UVa 11988 Broken Keyboard 题目大意: 小明没有开屏幕输入一个字符串,电脑键盘出现了问题会不定时的录入 home end ...

  2. UVA 11988 Broken Keyboard (链表)

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

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

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

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

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

  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(数组模拟链表)

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

  9. Uva 11988 Broken Keyboard

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

随机推荐

  1. MongoDB--操作符

    $gt -- > $lt -- < $gte -- >= $lte -- <= $all 与 in 类似,不同的是必须满足[]内所有的值 $exists 字段是否存在 db.s ...

  2. select change事件给其它元素赋值,本select的value或tex

    select change事件给其它元素赋值,本select的value或textonchange='$("#areaname").val($("option:selec ...

  3. php导入csv文件

    <?php /** * Created by PhpStorm. * User: hanks * Date: 2017/4/30 * Time: 13:24 */ include 'header ...

  4. 使用PHP二维码生成类库PHP QR Code生成二维码

    <?php include 'phpqrcode.php'; $value = 'http://www.helloweba.com'; //二维码内容 $errorCorrectionLevel ...

  5. php后台模板html拼接写法

    public function get_kefu_reply_list(){ $wid=$this->_post('order_id'); if(!$wid){ echo('工单信息获取失败!' ...

  6. js代码风格之链式结构

    <div class="box"> <ul class="menu"> <li class="level1"& ...

  7. 最全的CSS浏览器兼容问题(转至http://68design.net/Web-Guide/HTMLCSS/37154-1.html)

    最全的CSS浏览器兼容问题   CSS对浏览器的兼容性有时让人很头疼,或许当你了解当中的技巧跟原理,就会觉得也不是难事,从网上收集了IE7,6与Fireofx的兼容性处理方法并整理了一下.对于web2 ...

  8. [Android FrameWork 6.0源码学习] Window窗口类分析

    了解这一章节,需要先了解LayoutInflater这个工具类,我以前分析过:http://www.cnblogs.com/kezhuang/p/6978783.html Window是Activit ...

  9. Vijos 1025 小飞侠的游园方案 0-1背包

    描述 经过抽签选择,小智将军第一个进入考场. 菜虫:(身上散射出华贵(?)的光芒)欢迎你,第一位挑战者!! 小智:--(走到菜虫身后,关灯)女王陛下,虽然我们国家现在很富裕,但也请您不要浪费电来用这么 ...

  10. Tween 若干年后我尽然还要学数学 曲线到底是什么鬼啊

    var Tween = { linear: function (t, b, c, d){ //匀速 return c*t/d + b; }, easeIn: function(t, b, c, d){ ...