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)(链表)的更多相关文章

  1. 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 ...

  2. 破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988)

    破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988) 题意描述 你在输入文章的时候,键盘上的Home键和End键出了问题,会不定时的按下. ...

  3. 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 ...

  4. 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 ...

  5. 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:% ...

  6. UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)

    题目代号:UVA 11988 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&pa ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 百度云世界里的“七种武器”:PCS、BAE、Site App、ScreenX等

    如果说去年百度世界的关键词是“百度新首页”的话,那么今年在研发者人群中,对百度世界最深的印象就是“七种武器”,即在云的世界里,百度为开发者所提供的包括个人云存储.LBS.移动云测试中心等在内的七种工具 ...

  2. (C#)Windows Shell 外壳编程系列8 - 同后缀名不同图标?

    原文 (C#)Windows Shell 外壳编程系列8 - 同后缀名不同图标? (本系列文章由柠檬的(lc_mtt)原创,转载请注明出处,谢谢-) 接上一节:(C#)Windows Shell 外壳 ...

  3. 文本相似度算法——空间向量模型的余弦算法和TF-IDF

    1.信息检索中的重要发明TF-IDF TF-IDF是一种统计方法,TF-IDF的主要思想是,如果某个词或短语在一篇文章中出现的频率TF高,并且在其他文章中很少出现,则认为此词或者短语具有很好的类别区分 ...

  4. 74HC595的中文资料

    74HC595--具有三态输出锁存功能的8位串行输入.串行/并行输出移位寄存器 本文翻译自NXP的74HC595的datasheet 74HC595和74HCT595是带有存储寄存器和三态输出的8位串 ...

  5. 获取WebView里的网页文本内容

    获取WebView里的网页文本内容,能够採用例如以下方法: public class ComJSInterface { public void loadHtmlContent(String conte ...

  6. http://localhost:8080/ 演出Oracle说明

    输入http://localhost:8080,可以出现tomcat主页.并且我检查过啦,jdk.tomcat及oracle中的环境变量都设置对啦,可是安装oracle之后,再输入http://loc ...

  7. char*与char[]

    char *s1="hello";   // 指向常量区 char s2[]="hello";   // 指向数组的内存空间 char *s1 的s1是指针,指 ...

  8. Request.ServerVariables["Url"]

    Request.ServerVariables["Url"] 返回服务器地址 Request.ServerVariables["Path_Info"] 客户端提 ...

  9. UVa----------1594(Ducci Sequence)

    题目: 1594 - Ducci Sequence Asia - Seoul - 2009/2010A Ducci sequence is a sequence of n-tuples of inte ...

  10. PHP 判断数据类型

    isset()://变量是否已经声明 empty()://变量是否为空 defined()://常量是否已经定义 define() array_key_exists(mixed key, array ...