题目链接:

http://codeforces.com/problemset/problem/208/A

A. Dubstep

time limit per test:2 seconds
memory limit per test:256 megabytes
#### 问题描述
> Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
>
> Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
>
> For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
>
> Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.

输入

The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.

输出

Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.

样例

sample input

WUBWUBABCWUB

sample output

ABC

sample input

WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB

sample output

WE ARE THE CHAMPIONS MY FRIEND

题意

给你一串字母,求去掉分割标记"WUB"之后的句子。

题解

开一个缓存,直接模拟,匹配一个"WUB"之后把缓存里的值取出来,清空缓存然后跳过这个“WUB"继续做。

注意事项:退出循环之后要检查一下缓存里面是不是有东西。

(数据很小,用c++的string类做比较方便。)

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string>
using namespace std; const int maxn=1e6+10;
typedef long long LL; string str;
vector<string> ans; int n; int main(){
cin>>str;
string tmp="";
for(int i=0;i<str.length();i++){
if(i+2<str.length()&&str[i]=='W'&&str[i+1]=='U'&&str[i+2]=='B'){
if(tmp!=""){
ans.push_back(tmp);
}
tmp="";
i+=2;
}else{
tmp+=str[i];
}
}
if(tmp!="") ans.push_back(tmp);
for(int i=0;i<ans.size()-1;i++) cout<<ans[i]<<' ';
cout<<ans[ans.size()-1]<<endl;
return 0;
}

Codeforces Round #130 (Div. 2) A. Dubstep的更多相关文章

  1. Codeforces Round #130 (Div. 2) C. Police Station

    题目链接:http://codeforces.com/contest/208/problem/C 思路:题目要求的是经过1~N的最短路上的某个点的路径数 /  最短路的条数的最大值.一开始我是用spf ...

  2. Codeforces Round #130 (Div. 2)

    A. Dubstep 字符串模拟. string.find()用法 string str; size_t pos = str.find("WUB"); // 返回匹配的第一个位置 ...

  3. Codeforces Round #130 (Div. 2) C - Police Station 最短路+dp

    题目链接: http://codeforces.com/problemset/problem/208/C C. Police Station time limit per test:2 seconds ...

  4. Codeforces Round #580 (Div. 1)

    Codeforces Round #580 (Div. 1) https://codeforces.com/contest/1205 A. Almost Equal 随便构造一下吧...太水了不说了, ...

  5. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  6. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  7. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  8. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  9. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

随机推荐

  1. C# 匿名方法及Lambda表达式

    1.匿名方法 定义:匿名方法不能直接在类中定义,而是在给委托变量赋值的时候,需要赋值一个方法,此时可以“现做现卖”,定义一个匿名方法传递给该委托. 举实例说明: 实例一:无参数,无返回值的一个匿名方法 ...

  2. spark写入Oracle 报错 java.lang.ArrayIndexOutOfBoundsException: -32423

    原因: oracle 10g的驱动执行的批量提交只支持32768个参数,如果表的字段多于32个,就会出现该异常 解决办法: 升级oracle的驱动版本,换成ojdbc6.jar

  3. iOS 高阶

    1.UIStoryBoard 2. segue跳转传值 3. UIColor配色 //1. 十进制配色 [UIColor colorWithRed:163.0/255.0 green:148.0/25 ...

  4. 关于iOS自定义UITabBar的几种方法

    作为iOS开发最常用的两个多视图控制器 NavigationController 和 TabBarController 已经很强大了,基本上在大部分的应用中都能看到它们的影子.但是在使用的过程中,系统 ...

  5. java随笔 乱腾腾的 一些东西

    调用requonse.getWriter()方法时可实现文本字符串数据输出,调用response.getOutputStream()方法可现实字节流数据的输出.两种输出方式threadlocal模式和 ...

  6. 判断不在Update Task中

    CALL FUNCTION 'TH_IN_UPDATE_TASK'   IMPORTING     IN_UPDATE_TASK = IN_UPDATE_TASK.  "0 then not ...

  7. C# Winform中DataGridView的DataGridViewCheckBoxColumn使用方法

    下面介绍Winform中DataGridView的DataGridViewCheckBoxColumn使用方法: DataGridViewCheckBoxColumn CheckBox是否选中 在判断 ...

  8. WPF 类型“System.ComponentModel.ISupportInitialize”在未被引用的程序集中定义。

    问题:类型“System.ComponentModel.ISupportInitialize”在未被引用的程序集中定义.必须添加对程序集“System, Version=4.0.0.0, Cultur ...

  9. Android SDK 更新失败

    万恶的墙,调查兵团赶紧把墙拆了.大家一起跟巨人打一架. 解决方法是改hosts文件 添加 74.125.237.1 dl-ssl.google.com ok,good job 多亏了http://bl ...

  10. perl编程中的map函数示例

    转自:http://www.jbxue.com/article/14854.html 发布:脚本学堂/Perl  编辑:JB01   2013-12-20 10:20:01  [大 中 小] 本文介绍 ...