Codeforces Round #130 (Div. 2) A. Dubstep
2016-07-18 21:32
323 查看
题目链接:
http://codeforces.com/problemset/problem/208/AA. 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
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; }
相关文章推荐
- ABAP POPUP_TO_CONFIRM 弹出框总结
- List转JSON异常错误
- SSH-key 的相关问题
- 安卓项目之淘忆2.0的界面设计部分二
- 【CodeForces】[25A]IQ test
- node.js之lodash介绍
- 使用IDE工具进行程序的导入导出
- Java中的接口
- Android Studio运行时finished with non-zero exit value 1 或:app:transformClassesWithDexForNduoDebug
- 史上最全IO框架十(字符串流:属于字符流)
- nginx配置非80端口访问不了
- Android开发之Bundle与Intent详解
- UVA10892LCM Cardinality
- Android广播错误.MainActivity$MyReceiver; no empty constructor
- 【转载】使用C#进行系统编程
- 最小公倍数 最大公约数
- MySQL数据库操作
- Builder模式处理多个构造器
- JDBC基础
- POJ 1270 Following Orders(dfs/next_permutation())