Codeforces Round #130 (Div. 2) A. Dubstep
题目链接:
http://codeforces.com/problemset/problem/208/A
A. Dubstep
time limit per test:2 secondsmemory 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
WUBWUBABCWUBsample output
ABCsample input
WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUBsample 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的更多相关文章
- Codeforces Round #130 (Div. 2) C. Police Station
题目链接:http://codeforces.com/contest/208/problem/C 思路:题目要求的是经过1~N的最短路上的某个点的路径数 / 最短路的条数的最大值.一开始我是用spf ...
- Codeforces Round #130 (Div. 2)
A. Dubstep 字符串模拟. string.find()用法 string str; size_t pos = str.find("WUB"); // 返回匹配的第一个位置 ...
- 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 ...
- Codeforces Round #580 (Div. 1)
Codeforces Round #580 (Div. 1) https://codeforces.com/contest/1205 A. Almost Equal 随便构造一下吧...太水了不说了, ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
随机推荐
- Javascript之拖拽库
在手机上运行触屏拖动时,我发现页面并没有反应,服务器端执行javascript在手机端与电脑端不能“相同式”实现(电脑端运行正常,而手机端不一样),这是为甚么呢? 首先,我们都知道javascript ...
- 最新32位和64位xp,win7,win8,win10系统大全(电脑装机版)
一.系统主要特点 1.安装维护方便快速 - 全自动无人值守安装,采用万能GHOST技术,安装系统过程只需3-5分钟,适 合新旧各种机型. - 集成常见硬件驱动,智能识别+预解压技术,绝大多数硬件可以快 ...
- win7开启远程桌面
1.启用windows防火墙 计算机管理----->服务----->Windows Firewall(双击进入,启动类型改为自动,点击应用,点击启动)2.启动gpedit.msc打开“本地 ...
- jquery设置元素readonly和disabled(checkbox只读)
jquery api中提供了对元素应用disabled和readonly属性的方法:1,readonly 代码示例: $('input').attr("readonly",&quo ...
- 【Unity3D】Unity3D之 Resources.Load 动态加载资源
[Unity3D]Unity3D之 Resources.Load 动态加载资源 1.Resources.Load:使用这种方式加载资源,首先需要下Asset目录下创建一个名为Resources的文件夹 ...
- OC4_遵守多个协议
// // Calulator.h // OC4_遵守多个协议 // // Created by zhangxueming on 15/6/24. // Copyright (c) 2015年 zha ...
- idea基本
IntelliJ IDEA特色功能 IDEA所提倡的是智能编码,是减少程序员的工作,IDEA的特色功能有以下25点:智能的选取在很多时候我们要选取某个方法,或某个循环或想一步一步从一个变量到整个类慢慢 ...
- Excel多条件筛选、公式填充
接到一个任务,由于数据操作人员不会使用编辑公式进而无法进行相关筛选,所以要我帮忙.好久不碰Excel了,那就试试看吧. 需求是这样子的(这里做了最大化的简化):要求判断条件,男50岁以上,女40岁以上 ...
- RHEL7 添加用户,含sudo权限
1.添加普通用户[root@server ~]# useradd book //添加一个名为book的用户 [root@server ~]# passwd book //修改密码 Changing p ...
- linux服务器git pull/push时提示输入账号密码之免除设置
1.先cd到根目录,执行git config --global credential.helper store命令 [root@iZ25mi9h7ayZ ~]# git config --global ...