UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)
题目代号:UVA 11988
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3139
You’re typing a long text with a broken keyboard. Well it’s not so badly broken. The only problem
with the keyboard is that sometimes the “home” key or the “end” key gets automatically pressed
(internally).
You’re not aware of this issue, since you’re focusing on the text and did not even turn on the
monitor! After you finished typing, you can see a text on the screen (if you turn on the monitor).
In Chinese, we can call it Beiju. Your task is to find the Beiju text.
Input
There are several test cases. Each test case is a single line containing at least one and at most 100,000
letters, underscores and two special characters ‘[’ and ‘]’. ‘[’ means the “Home” key is pressed
internally, and ‘]’ means the “End” key is pressed internally. The input is terminated by end-of-file
(EOF).
Output
For each case, print the Beiju text on the screen.
Sample Input
This_is_a_[Beiju]_text
[[]][][]Happy_Birthday_to_Tsinghua_University
Sample Output
BeijuThis_is_a__text
Happy_Birthday_to_Tsinghua_University
题目大意:'['出现相当于跳到开头输入,']'相当于跳到结尾,然后输出最终应该显示的模样。
解题思路:链表,但是链表太过于繁琐,不太方便,所以用数组模拟链表进行操作,详细参照算法竞赛与入门经典第二版,方法很巧妙,但是有点难理解,手动模拟一次操作然后思考一下就懂了。
代码:
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <fstream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <algorithm>
using namespace std;
# define pi acos(-1.0)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define For(i,n,a) for(int i=n; i>=a; --i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define Fo(i,n,a) for(int i=n; i>a ;--i)
typedef long long LL;
typedef unsigned long long ULL; const int MAXM=;
char s[MAXM];
int Next[MAXM]; int main()
{
//freopen("in.txt", "r", stdin);
int cur,last;//cur为光标位置,last为显示屏最后一个字符
while(~scanf("%s",s+))
{
memset(Next,,sizeof(Next));
int len = strlen(s+);
Next[] = ;
cur = last = ;
for(int i = ; i <= len; i++)
{
if(s[i] == '[')
cur = ;
else if(s[i] == ']')
cur = last;
else
{
//模拟插入链表过程
Next[i] = Next[cur];//第i个字符指向光标位置
Next[cur] = i;//光标指向下一个字符
if(cur == last)//只有光标在当前最后一个字符位置或是遇到]后才执行
last = i;
cur = i;//移动光标
}
}
for(int i = Next[]; i != ; i = Next[i])
printf("%c",s[i]);
printf("\n");
memset(s,,sizeof(s));
}
return ;
}
UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)的更多相关文章
- 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)
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)
题目传送门 题意:训练指南P244 分析:链表模拟,维护链表的head和tail指针 #include <bits/stdc++.h> using namespace std; const ...
- UVa 11988 Broken Keyboard (a.k.a. Beiju Text)
题目复制太麻烦了,甩个链接 http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18693 直接模拟光标操作时间复杂度较高,所以用链 ...
- 暑假集训单切赛第二场 UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(字符串处理)
一开始不懂啊,什么Home键,什么End键,还以为相当于括号,[]里的东西先打印出来呢.后来果断百度了一下. 悲催啊... 题意:给定一个字符串,内部含有'['和']'光标转移指令,'['代表光标移向 ...
- UVa 11988 - Broken Keyboard (a.k.a. Beiju Text) 题解
刘汝佳的题目,悲剧文本 -_-||| 这里使用vector<string>容器倒置记录数据,然后从后面输出就能够了. 难度就是不知道这种文档究竟哪里是開始输出,故此使用动态管理内存的容器比 ...
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text) (链表,模拟)
使用list来模拟就行了,如果熟悉list,那么这道题真是分分钟秒掉... list是双向循环链表,插入和删除操作非常快,缺点是不能像数组一样随机按下标读取. 一下是wiki上说明的相关函数:http ...
- uva - 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 i ...
- 破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988)
破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988) 题意描述 你在输入文章的时候,键盘上的Home键和End键出了问题,会不定时的按下. ...
随机推荐
- C语言作业09
问题 答案 这个作业属于那个课程 C语言程序设计 这个作业要求在哪里 https://i.cnblogs.com/EditPosts.aspx?opt=1 我在这个课程的目标是 在学好C语言编程的基础 ...
- CSS3新特性(阴影、动画、渐变)
一.阴影 1.1文字阴影: text-shadow<length>①: 第1个长度值用来设置对象的阴影水平偏移值.可以为负值 <length>②: 第2个长度值用来设置对象的阴 ...
- Tomcat 调优的技巧 (转)
描述 最近在补充自己的短板,刚好整理到Tomcat调优这块,基本上面试必问,于是就花了点时间去搜集一下tomcat调优都调了些什么,先记录一下调优手段,更多详细的原理和实现以后用到时候再来补充记录,下 ...
- 10.jQuery之停止动画排队stop方法(重点)
重点:stop,在实际项目中,这个细节很重要 <style> * { margin: 0; padding: 0; } li { list-style-type: none; } a { ...
- H5头部meta标签的作用
<!DOCTYPE html> H5标准声明,使用 HTML5 doctype,不区分大小写 <head lang=”en”> 标准的 lang 属性写法 <meta ...
- BTE增强解析
原理:转载http://blog.csdn.net/wbin9752/article/details/7954663 BTEs(Business Transaction Events),是SAP的一种 ...
- openapi
https://www.breakyizhan.com/swagger/2810.html https://www.cnblogs.com/serious1529/p/9318115.html htt ...
- C++ 数据类型提高+内存四区
# 这一章节全部是C语言的内容# 数据类型提高**注意**1.数组作为形参会退化为指针(验证,传参后用sizeof进行打印,可以看出打印出数组的字节为一字节)2.形参在函数上和函数内是一样的,只不过对 ...
- C#使用反射机制获取类信息
1.用反射动态创建类实例,并调用其公有成员函数. //新建一个类库项目,增加一个GetSum方法. using System; namespace ClassLibrary1 { publi ...
- Wannafly挑战赛22 B 字符路径 ( 拓扑排序+dp )
链接:https://ac.nowcoder.com/acm/contest/160/B 来源:牛客网 题目描述 给一个含n个点m条边的有向无环图(允许重边,点用1到n的整数表示),每条边上有一个字符 ...