破损的键盘(悲剧文本)(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. Django—Model

    Django 模型是与数据库相关的,与数据库相关的代码一般写在 models.py 中,Django 支持 Sqlite3.MySQL.PostgreSQL 等数据库,只需要在 settings.py ...

  2. Flink Flow

    1. Create environment for stream computing StreamExecutionEnvironment env = StreamExecutionEnvironme ...

  3. CSS居中问题:块级元素和行级元素在水平方向以及垂直方向的居中问题

    元素的居中问题是每个初学者碰到的第一个大问题,在此我总结了下各种块级 行级 水平 垂直 的居中方法,并尽量给出代码实例. 首先请先明白块级元素和行级元素的区别 块级元素 块级元素水平居中 1:marg ...

  4. PHP 如何实现网址伪静态

    Apache的 mod_rewrite是比较强大的,在进行网站建设时,可以通过这个模块来实现伪静态. 主要步骤如下: 1.检测Apache是否开启mod_rewrite功能     可以通过php提供 ...

  5. xlwings: Write Excel macro using python instead of VBA

    i want to write Excel macros to deal with the data, but i am not familiar with VBA language. so i de ...

  6. python itchat 微信开发

    使用itchat可以简单操作微信,进行好友和群消息的发送 安装: pip install itchat 使用: import itchat, time # 登录 itchat.auto_login(h ...

  7. NSJSONSerialization能够处理的JSONData

    NSJSONSerialization能够处理的JSONData You use the NSJSONSerialization class to convert JSON to Foundation ...

  8. CVE-2015-1642 POC

    月初,玄武实验室的“每日安全动态”推送了一篇office UAF漏洞利用的文章,之前对office上UAF漏洞利用占位问题有些疑问,刚好就借助这篇文章重现了一下.其中堆喷射部分不是特别稳定,漏洞成因和 ...

  9. c# HttpWebRequest与HttpWebResponse

    [转]c# HttpWebRequest与HttpWebResponse 绝技 如果你想做一些,抓取,或者是自动获取的功能,那么就跟我一起来学习一下Http请求吧. 本文章会对Http请求时的Get和 ...

  10. 如何在SAP C4C里使用ABSL消费第三方Restful API

    首先我们得有一个可以正常工作的Restful API: 然后在Cloud for Customer的Cloud Application Studio里创建Restful API的模型,把第一步可以正常 ...