-
时间:2016-03-23 00:06:45 星期三
-
题目编号:[2016-03-23][codeforces][208][A][Dubstep]
-
题目大意:把字符串中的 “WUB”去掉
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int main(){
string str,s;
cin>>str;
int m = str.length();
vector<string> v;
for(int i = 0 ; i < m;++i){
if(i + 2 < m && str[i] == ‘W‘ && str[i + 1] == ‘U‘ && str[i + 2] == ‘B‘){
i += 2;
if(s != ""){
v.emplace_back(s);
s = "";
}
}else s += str[i];
}
if(s != ""){
v.emplace_back(s);
s = "";
}
m = v.size();
for(int i = 0 ;i < m - 1 ;++i){
cout<<v[i]<<‘ ‘;
}
cout<< v[m - 1] <<‘\n‘;
return 0;
}
#include <cstdio>
#include<cstring>
using namespace std;
char str[200 + 10];
int main(){
gets(str);
int m = strlen(str),cur = 0,flg = 0;
for(int i = 0; i < m ;++i){
if(i + 2 < m && str[i] == ‘W‘ && str[i + 1] == ‘U‘ && str[i + 2] == ‘B‘){
i += 2;
if(flg) str[cur++] = ‘ ‘;
}else {
str[cur++] = str[i];
flg = 1;
}
}
str[cur] = ‘\0‘;
printf("%s\n",str);
return 0;
}
时间: 2024-11-04 23:28:17