题目代号: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. Maven从入门到精通(一)

    maven是一个项目管理工具,我的后续将会根据这个思维导图给大家由浅到深讲解Maven是如何管理我们的项目,以及我们如何更好的使用Maven maven在开发过程中功能主要有三个方面:   管理依赖 ...

  2. Linux 下面根据端口号 查询 可执行程序的路劲的方法

    1. 安装上lsof 的包 2. 使用 lsof 命令查看相关进程 lsof -i: 效果为: 3. 根据/proc 的目录查看可执行目录的文件位置 ll /proc/procid # procid ...

  3. 小记---------网页采集之selenium

    1.元素定位 ID定位元素:  findElement(By.id(“”));  通过元素的名称定位元素:  findElement(By.name(“”));   通过元素的html中的位置定位元素 ...

  4. Java 创建bat命令文件运行可执行jar包

    在可执行jar包所在文件夹下创建txt文件(必须在同一文件夹目录下),打开创建的txt文件输入如下内容并保存: @echo off java -jar 包名.jar pause 如下图所示: 然后将后 ...

  5. java 线程池 - ThreadPoolExecutor

    1. 为什么要用线程池 减少资源的开销 减少了每次创建线程.销毁线程的开销. 提高响应速度 ,每次请求到来时,由于线程的创建已经完成,故可以直接执行任务,因此提高了响应速度. 提高线程的可管理性 ,线 ...

  6. 2019icpc徐州网络赛

    A Who is better? 题意 excrt+斐波那契博弈 分析 Java的BigInteger对象默认为null,不能直接比较. 代码 import java.math.BigInteger; ...

  7. Java Script 基本知识点

                          JavaScript是一种基于对象和事件驱动的脚本语言,它提供了一些专有的类.对象及函数 1.基本数据类型 JavaScript提供了4种基本的数据类型用来 ...

  8. kibana报[FORBIDDEN/12/index read-only / allow delete (api)]错误

    一.错误描述 1.在kibana,dev中pose数据,报[FORBIDDEN/12/index read-only / allow delete (api)]错误. 尝试过网上的说的方法一:在kib ...

  9. Linux常用命令及Shell的简单介绍

    一.linux命令   1.查看指令的参数搭配: man 指令名称   2.基础指令 ls  列出当前目录下的所有文档的名称(文档指的是文件和文件夹) 常用参数搭配: ls -l 列出文档详细信息 l ...

  10. Vue安装与简单使用

    Vue入门 使用Typora打开https://pan.baidu.com/s/1Mf3ZFSthdVUQevqWr777eA 提取码: hg9b vue中文官网教学 安装与使用,我也经常看这个 点击 ...