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键出了问题,会不定时的按下. ...
随机推荐
- Active Directory Users and Computers 安装与使用(win7&win10)
一. ADUC安装 根据自己电脑所使用的Windows操作系统,找到对应的ADUC管理工具补丁包点击下载后安装. Windows7补丁下载链接:https://www.microsof ...
- Spark架构角色及基本运行流程
1. 集群角色 Application:基于spark的用户程序,包含了一个Driver program 和集群中多个Executor Driver Program:运行application的mai ...
- Thread 线程 1
Thread 常用方法: String getName() 返回该线程的名称. void setName(String name) 改变线程名称,使之与参数 name 相同. int getPrior ...
- Layui数据表格的接口数据请求方式为Get
Layui数据表格的接口数据请求方式为Get
- django-restframework使用
安装restframework: pip install djangorestframework 修改项目settings.py: INSTALLED_APPS = [ 'django.contrib ...
- CRF++的使用(待更新)
1.下载CRF++(Windows和Linux两个版本) 2.目录如下: 主要用到crf_learn.exe ,crf_test.exe和libcrfpp.dll三个文件 doc文件夹:官方主页 ex ...
- vue与angular 区别
1.vue的双向数据绑定是基于 Es5中的getter和setter来实现的,而angular而是由自己实现的一套模板编译规则,需要进行 ‘脏’ 检查,vue则不需要,因此,vue性能上更高一些,但是 ...
- C++ 程序设计语言
好记性不如烂笔头. 第六章 标准库给出了静态断言,形式类似如下: stastic_assert(A,S);//当A不为true时,把S作为一条编译器错误信息输出 其最重要的用途是为泛型编程中作为形参的 ...
- Interviewe HDU - 3486 (ST表+枚举 )(非二分,看下这个数据、)
YaoYao has a company and he wants to employ m people recently. Since his company is so famous, there ...
- Codeforces 987 K预处理BFS 3n,7n+1随机结论题/不动点逆序对 X&Y=0连边DFS求连通块数目
A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_bac ...