UVA11988:Broken Keyboard (a.k.a. Beiju Text)
2015-06-15 09:48
357 查看
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
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 <iostream> #include <stdio.h> #include <string.h> #include <string> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <math.h> #include <bitset> #include <list> #include <algorithm> #include <climits> using namespace std; #define lson 2*i #define rson 2*i+1 #define LS l,mid,lson #define RS mid+1,r,rson #define UP(i,x,y) for(i=x;i<=y;i++) #define DOWN(i,x,y) for(i=x;i>=y;i--) #define MEM(a,x) memset(a,x,sizeof(a)) #define W(a) while(a) #define gcd(a,b) __gcd(a,b) #define LL long long #define N 100005 #define MOD 1000000007 #define INF 0x3f3f3f3f #define EXP 1e-8 #define lowbit(x) (x&-x) char str ; int next ; int main() { int i,j,cur,last; while(gets(str+1)) { int len = strlen(str+1); cur = last = 0; next[0] = 0; for(i = 1; i<=len; i++) { if(str[i]=='[') cur = 0; else if(str[i]==']') cur = last; else { next[i] = next[cur]; next[cur] = i; if(last == cur) last = i; cur = i; } } for(i = next[0]; i; i = next[i]) printf("%c",str[i]); puts(""); } return 0; }
相关文章推荐
- 设计模式(备忘录模式)
- IOS开发常见第三方总结
- weblogic部署项目缓存问题
- c++学习整理
- 我为什么选择51cto网络视频教育
- phaser续 接上
- lhgDialog窗口组件
- Fragment中使用menu的方法
- 快速排序,c++ 模板技术表述,完全兼容标准库!!!
- 开始刷leetcode day41:Implement strStr()
- 浅谈Java转义符\\|
- 【OGG】 RAC环境下管理OGG的高可用 (五)
- 【OGG】RAC环境下配置OGG单向同步 (四)
- hihoCoder挑战赛12 永恒游戏 模拟
- TextField控件、PasswordField控件、TextArea控件、Toggle 控件、ToolBar控件
- IntelliJ IDEA使用
- XUL的功能
- jsp实现分页技巧
- Hibernate 事务管理
- myeclipse中如何配置jdk1.7