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.另外一 ...
随机推荐
- 封装类似thinkphp连贯操作数据库的Db类(简单版)。
<?php header("Content-Type:text/html;charset=utf-8"); /** *php操作mysql的工具类 */ class Db{ ...
- map中根据value获取key
public static String getKeyByValue(Map map, Object value) { String keys=""; Iterator it = ...
- HDU - 1171 Big Event in HDU 多重背包
B - Big Event in HDU Nowadays, we all know that Computer College is the biggest department in HDU. B ...
- swfupload原理总结
1.引入js(js内动态添加上传的文件并提交表单) 2.后台处理(将图片保存) 3.调用另一个js修改前台图片的地址(改为新的图片地址)
- Linear Algebra - Determinant(几何意义)
二阶行列式的几何意义 二阶行列式 \(D = \begin{vmatrix}a_1&a_2\\b_1&b_2\end{vmatrix} = a_1b_2 - a_2b_1\) 的几何意 ...
- js转义字符
\" \/ \" 例: span = "<span onclick=\"xadmin.open('编辑','\/junyi\/member\/up ...
- JS 识别生日、性别、年龄
<script> function IdCard(UUserCard,num){ if(num==1){ //获取出生日期 birth=UUserCard.substring(6, 10) ...
- 洛谷P3704 [SDOI2017]数字表格(莫比乌斯反演)
传送门 yyb大佬太强啦…… 感觉还是有一点地方没有搞懂orz //minamoto #include<cstdio> #include<iostream> #include& ...
- vue中params & query的比较
共同点: 1.都可以传值 2.在另外一个组件中传递值的时候,都是放在$route中 不同点: 1.传值时候,url的表现不一样 query /orderInfo?xxx=yyy&aaa=bbb ...
- [Leetcode]003. Longest Substring Without Repeating Characters
https://leetcode.com/problems/longest-substring-without-repeating-characters/ public class Solution ...