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 ...
随机推荐
- 多校5 HDU5787 K-wolf Number 数位DP
// 多校5 HDU5787 K-wolf Number 数位DP // dp[pos][a][b][c][d][f] 当前在pos,前四个数分别是a b c d // f 用作标记,当现在枚举的数小 ...
- ACM1998
/* 魔方阵,古代又称“纵横图”,是指组成元素为自然数1.2…n的平方的n×n的方阵, 其中每个元素值都不相等,且每行.每列以及主.副对角线上各n个元素之和都相等. 输入一个奇数,实现奇数魔方阵. 附 ...
- leetcode—Swap Nodes in Pairs
1.题目描述 Given a linked list, swap every two adjacent nodes and return its head. For example, Given ...
- Create a commit using pygit2
Create a commit using pygit2 Create a commit using pygit2 2015-04-06 10:41 user1479699 imported from ...
- JSF 2 graphicImage example
In JSF, you can use <h:graphicImage /> tag to render a HTML "img" element. For examp ...
- C++获取系统的Mac地址
C++获取系统的Mac地址,加上libnetapi32.a #include <windows.h> #include <stdlib.h> #include <stdi ...
- ecshop收货人信息中修改手机号为必填
Ecshop 修改收货人信息 把电话改成选择填写 手机改为必填 (加强版) 1. 编辑根目录/js/utils.js 增加手机号码的正则表达式 参照Utils.isTel = function ( ...
- 【转】移动端App测试实用指南
转自:互联网那点事 英文原文: http://mobile.smashingmagazine.com/2012/10/22/a-guide-to-mobile-app-testing/ 测试人员常被看 ...
- hdu 5534 Partial Tree 背包DP
Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules) C. Letter 暴力
C. Letter Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/180/problem/C D ...