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.另外一 ...
随机推荐
- 【CodeVS 5032】【省队集训2016 Day5 T1】Play with array
一开始我用分块大法,分成$\sqrt{n}$块,每个块上维护一个Splay,然后balabala维护一下,时间复杂度是$O(n\sqrt{n}logn)$.后来对拍的时候发现比$O(n^2)$的暴力跑 ...
- 【BZOJ 2733】【HNOI 2012】永无乡 Splay启发式合并
启发式合并而已啦,, 调试时发现的错误点:insert后没有splay,把要拆开的树的点插入另一个树时没有把ch[2]和fa设为null,找第k大时没有先减k,,, 都是常犯的错误,比赛时再这么粗心就 ...
- 逻辑回归&&code
没有正则化项的时候的二分类 #-*-coding=utf-8-*- from numpy import loadtxt,where, transpose import matplotlib.pyplo ...
- 大屏iPhone的适配 +iOS 图片尺寸要求
摘自:http://blog.ibireme.com/2014/09/16/adapted_to_iphone6/ 苹果公司官网设计介绍到:Retina显示屏的超高像素密度已超过人眼能分辨的范围.Re ...
- codeforces Hill Number 数位dp
http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits: 5000 MS Memory Limits: ...
- dede使用方法----如何在wamp环境下安装dede
dede是基本php编写的一套框架,因此在使用dede之前必须要先搭建一上php的环境.本篇文章首先讲述如何搭建一个wamp环境,再讲述如何安装dede. 准备工具:wamp , dedeCMS 1. ...
- 用git管理源代码
自从做iOS开发的一年多以来,之前一直都是用svn进行代码管理.因为工作需要,我也开始用git管理源代码.关于git的基本使用,在此做一个详细的介绍,希望能对初次接触git的人有所帮助! 本篇博客针对 ...
- awk 匹配不是 pattern 的内容
awk '/pattern/ {next} {print $0}' filename
- Leetcode Power of two, three, four
Given an integer, write a function to determine if it is a power of two. Hint: Could you solve it in ...
- 【BZOJ-1176&2683】Mokia&简单题 CDQ分治
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 1854 Solved: 821[Submit][St ...