题目代号: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)(链表)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 链表 UVA 11988 Broken Keyboard (a.k.a. Beiju Text)

    题目传送门 题意:训练指南P244 分析:链表模拟,维护链表的head和tail指针 #include <bits/stdc++.h> using namespace std; const ...

  4. UVa 11988 Broken Keyboard (a.k.a. Beiju Text)

    题目复制太麻烦了,甩个链接 http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18693 直接模拟光标操作时间复杂度较高,所以用链 ...

  5. 暑假集训单切赛第二场 UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(字符串处理)

    一开始不懂啊,什么Home键,什么End键,还以为相当于括号,[]里的东西先打印出来呢.后来果断百度了一下. 悲催啊... 题意:给定一个字符串,内部含有'['和']'光标转移指令,'['代表光标移向 ...

  6. UVa 11988 - Broken Keyboard (a.k.a. Beiju Text) 题解

    刘汝佳的题目,悲剧文本 -_-||| 这里使用vector<string>容器倒置记录数据,然后从后面输出就能够了. 难度就是不知道这种文档究竟哪里是開始输出,故此使用动态管理内存的容器比 ...

  7. UVA 11988 Broken Keyboard (a.k.a. Beiju Text) (链表,模拟)

    使用list来模拟就行了,如果熟悉list,那么这道题真是分分钟秒掉... list是双向循环链表,插入和删除操作非常快,缺点是不能像数组一样随机按下标读取. 一下是wiki上说明的相关函数:http ...

  8. 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 ...

  9. 破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988)

    破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988) 题意描述 你在输入文章的时候,键盘上的Home键和End键出了问题,会不定时的按下. ...

随机推荐

  1. 从零开始学习GDI+ (三) 画笔与画刷

  2. [转帖]查看ubuntu 各系统的内核版本

    查看ubuntu 各系统的内核版本 https://www.cnblogs.com/ranxf/p/6923311.html /etc/issue /proc/version 1.查看ubuntu版本 ...

  3. Zookeeper - zookeeper安装与配置

    1.什么时Zookeeper ZooKeeper:分布式服务框架 Zookeeper -- 管理分布式环境中的数据. 2.安装 1>官网下载压缩包并解压zookeeper-3.4.14.zip ...

  4. java 集合 队列(Queue)

    特点:特殊线性表,先进先出(FIFO first-in-first-out) 方法: java5中 添加java.util.Queue接口,java.util.Collection 的扩展类 add( ...

  5. P1216数字三角形

    这是USACO的一道记忆化搜索题,还记得原来学搜索就是被此所困. 给定n深的数,第i层有i个节点,存储有一个数字,询问从第一层走到最后一层所经过节点上数字和的最大值.我们很容易想到枚举所有路径来计算最 ...

  6. Let和Const的使用

    ES2015(ES6) 新增加了两个重要的 JavaScript 关键字: let 和 const. let 声明的变量只在 let 命令所在的代码块内有效,const 声明一个只读的常量,一旦声明, ...

  7. Jquery复习(九)之noConflict()

    如何在页面上同时使用 jQuery 和其他框架? jQuery 和其他 JavaScript 框架 正如您已经了解到的,jQuery 使用 $ 符号作为 jQuery 的简写. 如果其他 JavaSc ...

  8. Jmeter读取CSV文件,请求参数乱码

    Jmeter读取CSV文件,请求参数乱码 1.修改本地配置文件,jmeter.properties,修改以下配置项 sampleresult.default.encoding=UTF-8 重启Jmet ...

  9. python3:tuple元组

    https://www.runoob.com/python3/python3-tuple.html 元组使用小括号,列表使用方括号. 元组创建很简单,只需要在括号中添加元素,并使用逗号隔开即可. Py ...

  10. vue学习【三】vue-router路由显示多页面

    大家好,我是一叶,今天是七夕,单身狗的我还在这里写踩坑文.在这里还是要祝大家早日脱单(能不能脱单自己心里没个数吗).本篇继续踩坑,在单页面上展示多页的内容,大家的想法是什么,估计大家第一印象会是ifr ...