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 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
题解:
给定一个字符串,内部含有”【“和”】“光标转移指令,
【代表光标移向文章头,】代表光标移向文章尾,问最终在屏幕上显示的字符串序列是?
Cur代表当前光标的位置,en代表当前结束的位置。。。模拟输入就好了,用链表;
链表,好题,代码好吊,看了半天,越看越感觉吊;
代码:
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=1e5+100;
int en,cur,next[MAXN];
char s[MAXN];
int main(){
while(~scanf("%s",s+1)){
int len=strlen(s+1);
cur=en=0;
next[0]=0;
for(int i=1;i<=len;i++){
if(s[i]=='[')cur=0;
else if(s[i]==']')cur=en;
else{
next[i]=next[cur];
next[cur]=i;
if(cur==en)en=i;
cur=i;
}
}
for(int i=next[0];i!=0;i=next[i])printf("%c",s[i]);
puts("");
}
return 0;
}
uva - Broken Keyboard (a.k.a. Beiju Text)(链表)的更多相关文章
- 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 ...
- 破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988)
破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988) 题意描述 你在输入文章的时候,键盘上的Home键和End键出了问题,会不定时的按下. ...
- 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 ...
- 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 ...
- 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)(链表)
题目代号: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 ...
- 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 ...
随机推荐
- JAVA GUI学习 - JList列表、JScrollPane滚动条组件学习
/** * 本例结合JList和JScrollPane共同使用 * @author Wfei * */ public class JListKnow extends JFrame { JList jL ...
- 记NOIP分数出来前
咩~成绩还没有出来呢!但是拿到了每个人的程序,还有一堆民间的数据.我测了好多不同的数据,基本上D1T1,D2T1,D2T2的都是暴力解决掉的,没有什么问题,唯一就是D1T2的link那一题,写的时候2 ...
- 首页 导航栏隐藏 下一级页面显示,pop回来遇到的问题
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationContr ...
- POJ1797 Heavy Transportation 【Dijkstra】
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 21037 Accepted: ...
- 具体解释VMware 9.0.1安装MAC OS X 10.8(历时近3日感想篇)
突然心血来潮,想用VMware 9.0.1安装MAC OS X,但网上的文章多多少少总有点缺陷,不能适合每个人,在综合了近30篇安装MAC OS X的文章后,我决定公布一篇比較大众化,比較详尽的MAC ...
- citrix协议ICA技术原理
转载自: http://www.zrss.com.cn/article-110-1.html Citrix交付中心解决方式的核心是虚拟化技术,虚拟化计算的核心是ICA协议,ICA协议连接了执行在平台上 ...
- Android JNI入门第一篇——HelloJni
android支持使用NDK开发C程序,关于配置NDK环境问题应该不用再赘述了,这个网上有很多,这里通过一篇实例来讲述简单的JNI开发,大家可以参考这篇文章(Get Your Eclipse-Inte ...
- 通过OC实现简单的冒泡排序
NSMutableArray *arr = [@["] mutableCopy]; ; i<[arr count]-; i++) { ; j<[arr count]--i; j+ ...
- MBProgressHUD简单使用
使用HUD最多的情形用于请求等待提示 例如做登录的时候在确认登陆的时候可以用HUD提示正在登陆. 最基本的使用 初始化 //self.view代表在哪个view中显示hud MBProgressHUD ...
- Definitions
Definitions and ODR Definitions are declarations that fully define the entity introduced by the decl ...