UVa 11988 Broken Keyboard(链表->数组实现)
/*数组形式描述链表:链表不一定要用指针。
题目链接: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(链表->数组实现)的更多相关文章
- 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 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)
题目代号:UVA 11988 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&pa ...
- 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 ...
- UVa 11988 Broken Keyboard(数组模拟链表)
题目链接: https://cn.vjudge.net/problem/UVA-11988 /* 问题 将一段文本经过一定的规则处理后输出,规则就是[表示home键,表示光标跳到行首,]表示end键, ...
- Uva 11988 Broken Keyboard STL+链表
两种方法,直接上代码 STL标准模板库 #include <iostream> #include <list> #include <algorithm> #incl ...
- 链表 UVA 11988 Broken Keyboard (a.k.a. Beiju Text)
题目传送门 题意:训练指南P244 分析:链表模拟,维护链表的head和tail指针 #include <bits/stdc++.h> using namespace std; const ...
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text) (链表,模拟)
使用list来模拟就行了,如果熟悉list,那么这道题真是分分钟秒掉... list是双向循环链表,插入和删除操作非常快,缺点是不能像数组一样随机按下标读取. 一下是wiki上说明的相关函数:http ...
- UVA 11988 Broken Keyboard (链表)
简单题,题目要求显然是很多次插入,所以是链表. 插入两个语句,nxt[i] = nxt[u] 表示 i结点指向u的后继, nxt[u] = i表示把u的后继设成i. 设置一个头结点,指向一个不存在的结 ...
- Uva 11988 Broken Keyboard
因为要经常移动这些字符,所以采用的数据结构是链表. next[i]起到的作用大概就是类似链表里的next指针. 0.需要注意的是,判断cur == last ? 如果 是 则 last=i 1.另外一 ...
随机推荐
- [转]VirtualBox – Error In supR3HardenedWinReSpawn 问题解决办法
原文地址:http://chenpeng.info/html/3510 Genymotion 模拟器安装好虚拟机后,启动时报错: —————————VirtualBox – Error In supR ...
- webuploader跨域上传
浏览器在跨域请求前会发个options请求来验证是否跨域,所以后端再处理这个options请求时,要告诉浏览器一些信息. 也就是个header信息 header("Access-Contro ...
- Struts中Action三种接收参数的方式?
前言: 前面已经有一篇随笔介绍了Struts2的大概原理.本文就Struts2中Action与jsp页面进行数据对接时介绍几种常见方法! 值栈ValueStack 3个Action Action1 p ...
- 算法求和sum问题
问题:SUM(n) = 1 + 2 + 3 + ... + n写个算法 回答: #include<stdio.h>int main(){ int n,sum; while(sc ...
- Java多线程与并发库高级应用-同步集合
ArrayBlockingQueue LinkedBlockingQueue 数组是连续的一片内存 链表是不连续的一片内存 传统方式下用Collections工具类提供的synchronizedCo ...
- 【matlab】设定C++编译器
在用matlab2016a,运行的代码涉及到C++混编,要用mex把C++代码编译出来. 记得几年前的matlab版本,通过: mex -setup 就可以设定了,选择要使用的编译器(文本的超链接), ...
- springMVC-自定义数据类型转换器
自定义类型转换器 201603005,今天想了一个问题,Spring中的Conventer是如何实现的,因为他没有绑定类中的属性,它怎么知道要将那个String转换?看了几遍的书也没有找到,后来想想, ...
- [Noi2016十连测第五场]二进制的世界
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- npm配置文件
npm获取配置的方式,优先级由高到底. 命令行参数. 以设置代理为例:--proxy http://server:port即将proxy的值设为http://server:port. 环境变量. 以n ...
- python json.dumps() json.dump()的区别
以前写的很简单,只有几句话,最近发现本文是本博客阅读量最大的一篇文章,觉得这样有种把人骗进来的感觉,于是又细化了一些.如果还有不好的地方,欢迎指出. 首先说明基本功能: dumps是将dict转化成s ...