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

题意描述

你在输入文章的时候,键盘上的Home键和End键出了问题,会不定时的按下。你却不知道此问题,而是专心致志地打稿子,甚至显示器都没开。当你打开显示器之后,展现你面前的数一段悲剧文本。你的任务是在显示器打开前计算出这段悲剧的文本。 给你一段按键的文本,其中'['表示Home键,']'表示End键,输入结束标志是文件结束符(EOF)。

样例输入

This_is_a_[Beiju]_text

[[]][][]Happy_Birthday_to_Tsinghua_University

样例输出

BeijuThis_is_a__text

Happy_Birthday_to_Tsinghua_University

实现

#include<bits/stdc++.h>
using namespace std;
int main(){
string line;
while(getline(cin,line)){
deque<string> result;
string str;
int flag=1;//flag=1 push_back,flag=0 push_front
for(int i=0;i<line.length();i++){
if(line[i] == '['){flag=0;}
else if(line[i] == ']'){
if(!str.empty()){
result.push_front(str);
str.clear();
}
flag=1;}
else{//normal c or _
if(flag){
string s;
s.push_back(line[i]);
result.push_back(s);
}
else {
str=str+line[i];
}
}
}
deque<string>::iterator it;
for(it=result.begin();it!=result.end();++it){
cout<<*it;
}
cout<<endl;
}
}

破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988)的更多相关文章

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

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

    题目链接:https://vjudge.net/problem/UVA-11988 题目大意:输入一个字符串,输出在原本应该是怎么样的?  具体方法是 碰到' [ ' 回到最前面  碰到‘ ]’  回 ...

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

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

  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)

    11988 Broken Keyboard (a.k.a. Beiju Text)You’re typing a long text with a broken keyboard. Well it’s ...

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

  8. UVa 11988 - Broken Keyboard (a.k.a. Beiju Text) 题解

    刘汝佳的题目,悲剧文本 -_-||| 这里使用vector<string>容器倒置记录数据,然后从后面输出就能够了. 难度就是不知道这种文档究竟哪里是開始输出,故此使用动态管理内存的容器比 ...

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

随机推荐

  1. ajax方法XHR.readyState五种状态与示例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. css 样式表集合

    说到前端不得不说一下css样式 css样式是用来装饰我们的html让整个页面显得更丰富多彩,所以我们要熟悉各种css样式,本人搜集了一下 供大家参考一下 字体属性:(font) 大小 {font-si ...

  3. 学习C++从入门到精通的的十本最经典书籍

    原文:http://blog.csdn.net/a_302/article/details/17558369 最近想学C++,找了一下网上推荐的书籍,转载过来给大家分享 转载自http://c.chi ...

  4. Python爬虫教程-16-破解js加密实例(有道在线翻译)

    python爬虫教程-16-破解js加密实例(有道在线翻译) 在爬虫爬取网站的时候,经常遇到一些反爬虫技术,比如: 加cookie,身份验证UserAgent 图形验证,还有很难破解的滑动验证 js签 ...

  5. 提问的智慧 How To Ask Questions The Smart Way

    提问的智慧 How To Ask Questions The Smart Way Copyright © 2001,2006,2014 Eric S. Raymond, Rick Moen 本指南英文 ...

  6. 二十、滑动开关css

    如上图所示的图片,如何通过css实现呢? 下面咱们慢慢尝试: html: <div class="togglePosition"> <label class=&q ...

  7. python SQLAchemy外键关联

    join 1.利用filter import sqlalchemy from sqlalchemy import create_engine from sqlalchemy.ext.declarati ...

  8. Linux 安装问题

    问题1: root>sudo apt-get install yum 提示: dpkg was interrupted, you must manually run 'sudo dpkg --c ...

  9. g++: error: unrecognized command line option ‘-std=C++11’

    一个小程序,在编译的时候出错,原来使用的编译命令是 g++ -std=C++11 array.cpp -o array.exe g++: error: unrecognized command lin ...

  10. February 22 2017 Week 8 Wednesday

    There is only one happiness in life, to love and be loved. 生命中只有一种幸福,爱与被爱. If you think you are not ...