B - Broken Keyboard (a.k.a. Beiju Text)
Problem B
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 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). The size of input file does not exceed 5MB.
Output
For each case, print the Beiju text on the screen.
Sample Input
This_is_a_[Beiju]_text
[[]][][]Happy_Birthday_to_Tsinghua_University
Output for the Sample Input
BeijuThis_is_a__text
Happy_Birthday_to_Tsinghua_University
Rujia Liu's Present 3: A Data Structure Contest Celebrating the 100th Anniversary of Tsinghua University
Special Thanks: Yiming Li
Note: Please make sure to test your program with the gift I/O files before submitting!
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <cctype>
#include <cassert>
#include <typeinfo>
#include <utility> //std::move()
using namespace std;
const int INF = 0x7fffffff;
const double EXP = 1e-;
const int MS = ;
typedef long long LL;
int last, cur, nexti[MS]; //next[0-n] 0为虚拟节点,也是结束标记 链表法
char str[MS]; int main()
{
while (scanf("%s", str + ) == )
{
int len = strlen(str + );
last = cur = ; // 在0的后面增加下一个元素
nexti[] = ;
for (int i = ; i <= len; i++)
{
if (str[i] == '[')
cur = ;// 光标移动0这,在0的后面添加下一个元素
else if (str[i] == ']')
cur = last;
else
{
nexti[i] = nexti[cur];
nexti[cur] = i;
if (cur == last)
last = i;
cur = i;
}
}
for (int i = nexti[]; i != ; i = nexti[i])
printf("%c", str[i]);
printf("\n");
}
return ;
}
B - Broken Keyboard (a.k.a. Beiju Text)的更多相关文章
- 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键出了问题,会不定时的按下. ...
- N - Broken Keyboard (a.k.a. Beiju Text)(DFS,链表)
N - Broken Keyboard (a.k.a. Beiju Text) Time Limit:1000MS Memory Limit:0KB 64bit IO Format:% ...
- 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 ...
- 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 ...
- B - 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)(链表)
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)(链表)
题目代号:UVA 11988 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&pa ...
- Broken Keyboard (a.k.a. Beiju Text) UVA - 11988
You're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem wi ...
随机推荐
- 怎么使用PHPMailer实现邮件的发送??
来源:http://www.ido321.com/1103.html 发送邮件是常用的功能,LZ今天在项目中也碰到了,特此分享一下. 首先,去下载PHPMailer 1.https://github. ...
- 使用3D物体做GUI界面
通常来说,Unity自带的OnGUI不太好用,靠代码完成,在场景中无法直接编辑.所以,一般项目使用NGUI插件来做界面,但我这次要修改一个游戏,它没用NGUI,也没用OnGUI,而是使用类似NGUI的 ...
- 转】机器学习开源框架Mahout配置与入门研究
原博文出自于:http://www.ha97.com/5803.html 感谢! PS:机器学习这两年特别火,ATB使劲开百万到几百万年薪招美国牛校的机器学习方向博士,作为一个技术控,也得折腾下 ...
- 信息图:iOS 7开发者需要知道的事
如果你想为iOS 设备开发app,你需要知道如何与软件交互,如何设计,你还要知道苹果独特的开发理念和开发工具.真正的能力还需要成功地从其他行业领域借鉴核心概念.最后把所有这些东西糅合进你的信息库中 ...
- 黄金点游戏之客户端(homework-05)
0. 摘要 之前我们玩了2次黄金数游戏,我也幸运的得到了一本<代码大全>,嘿嘿.这次的作业是一个Client/Server程序,自动化完成多轮重复游戏. 我完成了Client部分,使用C# ...
- 使用Cygwin通过ssh命令行来访问Windows8
安装Cygwin可以参考<如何在Windows中通过Cygwin来使用Linux命令>. 在Win8下貌似有个bug,需要将cygwin\bin\mintty 修改为cygwin\bin\ ...
- Spring Autowiring by AutoDetect
In Spring, "Autowiring by AutoDetect", means chooses "autowire by constructor" i ...
- CentOS 搭建LNMP服务器和LAMP服务器
CentOS 搭建LNMP服务器 方法一:yum安装 1.更新YUM源 wget http://www.atomicorp.com/installers/atomic #下载atomic自动更新Y ...
- CPU与内存(经典问答)
原文:http://www.cnblogs.com/xkfz007/archive/2012/10/08/2715163.html 下面是网上看到的一些关于内存和CPU方面的一些很不错的文章. 整理如 ...
- 允许ubuntu下mysql远程连接
第一步: gedit /etc/mysql/my.cnf找到bind-address = 127.0.0.1 注释掉这行,如:#bind-address = 127.0.0.1 或者改为: bind- ...