Description
fjxmlhx hates marshtomp, so he wants to ignore the "marshtomp" in every sentences. In order to making the sentence complete, he changes the word "marshtomp" into "fjxmlhx"
please create a class, then you must solve the problem via calling the method of the class with the object of the class.
Input
the input contains several lines
each line there exists a string whose length is no more than 200
Attention: the end of line has nothing to do with the beginning of the next line
Output
print the answer of the problem
Sample Input
marshTomp is beaten by fjxmlhx!
AmarshtompB
Sample Output
fjxmlhx is beaten by fjxmlhx!
AfjxmlhxB
解析:这题利用find()和replace()函数十分简便,注意不区分大小写,所以我们得保存原字符串到一个数组中,然后原字符串数组转化成全小写,进行查找替换。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int i;
string a,a1,b="marshtomp",c="fjxmlhx";
while(getline(cin,a)){
a1=a; //保存一下
for(i=0;i<a.length();i++){
if(a[i]>='A'&&a[i]<='Z') a[i]=a[i]+32; //转化为小写
}
while(a.find(b)!=string::npos){ //如果找到
int pos=a.find(b); //确定位置
a.replace(pos,9,c); //替换
a1.replace(pos,9,c); //替换
}
cout<<a1<<endl;
}
return 0;
}