string handling -- Dubstep
http://codeforces.com/problemset/problem/208/A
A. Dubstep
In this question , we have to remove all "WUB" from a given string.
Sample test(s)
input
WUBWUBABCWUB
output
ABC
input
WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB
output
WE ARE THE CHAMPIONS MY FRIEND
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s,s1;
cin>>s;
s1="WUB";
int i,j,k,l;
l=s.length();
k=s.find(s1); /// "find()" returns the starting index of s1 in s
while(k!=-1)
{
s.replace(k,3," "); /// "replace()" function replace the 3 letters starting from kth index to " ";
k=s.find(s1);
}
cout<<s<<endl;
return 0;
}
Comments
Post a Comment