题目代号: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. centos 防火墙 iptables firewalld SELinux

    参考 Centos7 只启用iptables 禁用firewalld功能 java.net.NoRouteToHostException: 没有到主机的路由 相关内容 centos7 中才开始引用fi ...

  2. MySql 面试开发技术点汇总

    表结构设计 1.为什么一定要设一个主键?  答:因为你不设主键的情况下,innodb也会帮你生成一个隐藏列,作为自增主键.所以啦,反正都要生成一个主键,那你还不如自己指定一个主键,在有些情况下,就能显 ...

  3. php前台表单限制PHP上传大小

    在php文件上传时候,一般我都认为考虑php.ini配置修改文件上传大小,还后台控制上传大小,这里教你php前台表单限制PHP上传大小 <form action="http://www ...

  4. 【二】Django 视图和url配置

    在新建的Django项目下,新建一个views的python文件,编辑如下代码 from django.http import HttpResponse def hello(request): ret ...

  5. mysql在docker下运行,出现中文乱码

  6. Struts2对于BigDecimal类型的转换问题

    Struts2对常用的数据类型如String.Integer.Double等都添加了转换器进行对应的转换操作. BigDecimal其实也算作是一种常用的数据类型,但Struts2没有对该类型设置转换 ...

  7. fullpage实现(-)

    在线demo还没弄好,地址先给出来

  8. urlencode编/解码

    from urllib.parse import urlencode, quote, unquote # urlencode方法参数是字典 body = { "content": ...

  9. bcdedit删除uefi多余项

    1.检查是否有多余的启动项:用管理员权限的cmd运行Bcdedit /enum firmware 2.保存现在的所有引导项Bcdedit /export savebcdsavebcd是导出的文件名 3 ...

  10. Qt设置生成的exe文件图标

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/qq_37354286/article/d ...