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. 《UNIX环境高级编程》笔记--文件共享

    1.文件共享 内核使用3种数据结构来表示打开的文件,他们的关系如下: 每个进程都有一张进程表项,记录进程打开的文件: fd标志:close_on_exec,若一个文件描述符在close_on_exec ...

  2. BZOJ 3038 上帝造题的七分钟2 (并查集+树状数组)

    题解:同 BZOJ 3211 花神游历各国,需要注意的是需要开long long,还有左右节点需要注意一下. #include <cstdio> #include <cmath> ...

  3. config.json ajenti

    {    "users": {        "root": {            "configs": {               ...

  4. mac 如何显示隐藏文件和.点开头文件?

    如果想在Finder中就能直观看到隐藏文件,那么在终端中输入以下下命令: defaults write com.apple.Finder AppleShowAllFiles YES killall F ...

  5. myeclipse 8.6 插件安装之SVN

    在这里我要说明一点,myEclipse 8.6的插件安装和之前的版本可能会有一些区别,下面是SVN插件的安装: 1.从官网下载site-1.6.13.zip文件,网址是:subclipse.tigri ...

  6. QQ对话代码

    <li> <strong class="QQ">客服QQ</strong> <span> <a href="mqqw ...

  7. python成长之路——第八天

    pickle,load :切记:如果load的是个对象的话,必须导入构建这个对象的类     封装 类和对象的关系: 每个对象里都有一个类对象指针,指向类     继承:支持单继承和多继承 print ...

  8. python中os.walk浏览目录和文件

    #!/usr/bin/env python # 2.py # use UTF-8 # Python 3.3.0 # os.walk()的使用 import os # 枚举dirPath目录下的所有文件 ...

  9. cocos2dx进阶学习之CCDirector

    继承关系 CCDirecotor -> CCObject, TypeInfo 处理主窗口消息,管理何时.何种方式执行场景. 经常被翻译成导演,负责管理整个游戏的进程推动和周边支持. 成员 inl ...

  10. hdu 4679 (树形DP)

    题意:给一棵树,边的权值都是1,摧毁每条边是有代价的,选择摧毁一条边,把一棵树分成两部分,求出两部分中距离最大的两点的距离,求出距离*代价最小的边,多条的话输出序号最小的. 刚开始理解错题意了,wro ...