UVA 11988 Broken Keyboard (链表)
简单题,题目要求显然是很多次插入,所以是链表。

插入两个语句,nxt[i] = nxt[u] 表示 i结点指向u的后继, nxt[u] = i表示把u的后继设成i。
设置一个头结点,指向一个不存在的结点,维护一下最后一个结点tail。
#include<bits/stdc++.h>
using namespace std; const int maxn = 1e5+;
int nxt[maxn];
char s[maxn]; int main()
{
//freopen("in.txt","r",stdin);
while(gets(s+)){
int head = , cur = , tail = ; nxt[] = -;
for(int i = ; s[i]; i++){
if(s[i] == '[') cur = head;
else if(s[i] == ']') cur = tail;
else {
nxt[i] = nxt[cur];
nxt[cur] = i;
if(cur == tail) tail = i;
cur = i;
}
}
for(int i = nxt[head]; ~i; i = nxt[i] ){
putchar(s[i]);
}
putchar('\n');
}
return ;
}
UVA 11988 Broken Keyboard (链表)的更多相关文章
- UVa 11988 Broken Keyboard(链表->数组实现)
/*数组形式描述链表:链表不一定要用指针. 题目链接:UVa 11988 Broken Keyboard 题目大意: 小明没有开屏幕输入一个字符串,电脑键盘出现了问题会不定时的录入 home end ...
- 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 (a.k.a. Beiju Text)
题目传送门 题意:训练指南P244 分析:链表模拟,维护链表的head和tail指针 #include <bits/stdc++.h> using namespace std; const ...
- Uva 11988 Broken Keyboard STL+链表
两种方法,直接上代码 STL标准模板库 #include <iostream> #include <list> #include <algorithm> #incl ...
- UVa 11988 Broken Keyboard(数组模拟链表)
题目链接: https://cn.vjudge.net/problem/UVA-11988 /* 问题 将一段文本经过一定的规则处理后输出,规则就是[表示home键,表示光标跳到行首,]表示end键, ...
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text) (链表,模拟)
使用list来模拟就行了,如果熟悉list,那么这道题真是分分钟秒掉... list是双向循环链表,插入和删除操作非常快,缺点是不能像数组一样随机按下标读取. 一下是wiki上说明的相关函数:http ...
- Uva 11988 Broken Keyboard
因为要经常移动这些字符,所以采用的数据结构是链表. next[i]起到的作用大概就是类似链表里的next指针. 0.需要注意的是,判断cur == last ? 如果 是 则 last=i 1.另外一 ...
随机推荐
- ZOJ 3512 Financial Fraud (左偏树)
题意:给定一个序列,求另一个不递减序列,使得Abs(bi - ai) 和最小. 析:首先是在每个相同的区间中,中位数是最优的,然后由于要合并,和维护中位数,所以我们选用左偏树来维护,当然也可以用划分树 ...
- LightOJ - 1234 LightOJ - 1245 Harmonic Number(欧拉系数+调和级数)
Harmonic Number In mathematics, the nth harmonic number is the sum of the reciprocals of the first n ...
- 存储过程接收JSON格式数据
前端有可能一次性上传多笔记录,并使用JSON序列化. 现在在MS SQL Server 2016版本上,可以直接处理JSO数据. 如下面的前端序列化的数据: DECLARE @json_string ...
- Silhouette-Outlined Diffuse
http://wiki.unity3d.com/index.php/Silhouette-Outlined_Diffuse A variant of Outlined Diffuse 3 showin ...
- Codevs 1159 最大全0子矩阵
1159 最大全0子矩阵 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 在一个0,1方阵中找出其中最大的全 ...
- SpringBoot2.0 基础案例(11):配置AOP切面编程,解决日志记录业务
本文源码 GitHub地址:知了一笑 https://github.com/cicadasmile/spring-boot-base 一.AOP切面编程 1.什么是AOP编程 在软件业,AOP为Asp ...
- HTML5元素拖放设置总结
将元素图片放入div盒子内 1.首先设置元素为可拖放:在img标签内加入draggable=”true”. <img draggable="true"> 2.设置元素的 ...
- linux 查看系统版本号(转)
一.查看Linux内核版本命令(两种方法): 1.cat /proc/version [root@localhost ~]# cat /proc/versionLinux version 2.6.18 ...
- 黑马旅游网案例 Bug集锦
- shell编程 条件判断式----利用 if .... then ----多重
条件判断式----利用 if .... then ----多重 在同一个数据的判断中,如果该数据需要进行多种不同的判断时,应该怎么作?举例来说,上面的 sh06.sh 脚本中,我们只要进行一次 $yn ...