原文链接: http://codeforces.com/problemset/problem/208/A
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 200characters. 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 test(s)
WUBWUBABCWUB
ABC
WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB
WE ARE THE CHAMPIONS MY FRIEND
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
题目大意是:给你一个字符串,然后你的任务是把这个字符串中出现“WUB”以外的其他字母组成的单词输出来,而且根据题目给的测试例可知,单词和单词之间要有空格隔开
代码一:
#include<iostream>
#include<string.h> //strlen(s)用到这个头文件
using namespace std;
int main()
{
char s[202]; //字符串的长度不超过200(由题意可知)
while(cin>>s)
{
int i=0,t=0,k=0;
//处理字符串
for(i=0; i<strlen(s); i=i+t)
{
k=i;
if(s[i]=='W')
{
if(s[i+1]=='U')
{
if(s[i+2]=='B')
{
if(k!=0)
cout<<" ";
t=3;
}
else
{
cout<<s[i]<<s[i+1];
t=2;
}
}
else
{
t=1;
cout<<s[i];
}
}
else
{
t=1;
cout<<s[i];
}
}
}
return 0;
}
代码二:
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char s[202];
while(cin>>s)
{
int i=0, t=0,k=0;
for(i=0; i<strlen(s); i+=t)
{
k=i;
if(s[i]=='W')
{
if(s[i+1]=='U')
{
if(s[i+2]=='B')
{
t=3;
if(k!=0)
cout<<" ";
}
else
{
if(s[i+2]=='W')
{
t=2;
cout<<s[i]<<s[i+1];
}
else
{
t=2;
cout<<s[i]<<s[i+1];
}
}
}
else
{
if(s[i+1]=='W')
{
t=1;
cout<<s[i];
}
else
{
t=1;
cout<<s[i];
}
}
}
else
{
t=1;
cout<<s[i];
}
}
}
return 0;
}