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 ...
随机推荐
- Json.Net系列教程 1.Json.Net介绍及实例
原文 Json.Net系列教程 1.Json.Net介绍及实例 本系列教程假设读者已经对Json有一定的了解,关于Json在这里不多说.本系列教程希望能对读者开发涉及到Json的.Net项目有一定的帮 ...
- 共享内存操作类(C#源码)
原文 http://blog.csdn.net/yefanqiu/article/details/1717458 VC++的共享内存操作代码实现起来相对比较容易,但是用C#语言来实现,就有一定难度,由 ...
- vs2013搭建团队版本控制 TFS、SVN
项目使用vs2013开发,之前使用过svn进行版本控制,由于长时间未使用,记录备用. 一.TFS Team Foundation Server(TFS) 是微软提供的一个团队协同办公的管理工具,项目总 ...
- C语言实验——一元二次方程Ⅱ
C语言实验--一元二次方程Ⅱ Time Limit: 1 Sec Memory Limit: 64 MB Submit: 169 Solved: 131 [Submit][Status][Web ...
- SharePoint代码段设计
参考文章: 1. SharePoint 2013设计管理器代码段 https://msdn.microsoft.com/zh-cn/library/jj822367 2. 如何在SharePoint中 ...
- Enze Second day
哈喽,很高兴在云和学院又学了一天的新知识,现在,我来继续总结一下今天所学的以及对昨天的一些补充. 变量 • 声明变量的语法格式: –数据类型 变量名; •赋值: 变量名=值; 变量的命名 • ...
- CSS中overflow:hidden
CSS中,overfllow:hidden的作用是隐藏溢出 比如:<div style="width:300px;overflow:hidden" id=1><d ...
- CodeForce 569A
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Litt ...
- mina教程
关于mina介绍这里不做阐述..... 我们先做一个关于mina的helloworld 首先先下载mina包:http://mina.apache.org/ (如果你已经下载,此步骤忽略) 下载下来以 ...
- JavaScript 导学推荐
基本开始js学习的时候,可能会觉得很混乱,一开始都是从一些简单的表单验证还有拷贝别人效果代码,然后再慢慢去深入了解.我是觉得js是需要一定语言编程基础,我是觉得随着深入,JS的里面实在不算太好理解,个 ...