字符串代替——然而沼跃鱼早就看穿了一切
——然而沼跃鱼早就看穿了一切
fjxmlhx不喜欢网上的 marshtomps 。所以他决定把所有的 “marshtomp”(名字不区分大小写) 改为 “fjxmlhx;
Input
输入包含多行,每行字符串不超过200的长度,一个单词不会一半出现在上一行,剩下的在下一行。直到文件结束(EOF)
Output
输出 替换之后的字符串。
Sample Input
The Marshtomp has seen it all before. marshTomp is beaten by fjxmlhx! AmarshtompB
Sample Output
The fjxmlhx has seen it all before. fjxmlhx is beaten by fjxmlhx! AfjxmlhxB
1 #include<iostream>
2 #include<string>
3 #include<algorithm>
4 using namespace std;
5
6 int main(){
7 string s;
8 string m("marshtomp");
9 string f("fjxmlhx");
10 while(getline(cin,s)){
11 string t;
12 t=s;
13 transform(t.begin(),t.end(),t.begin(),::tolower);//将所有的大写转换为小写
14 string::size_type pos=0;
15 int len=s.length();
16 while((pos=t.find(m,pos))<len){
17 s.replace(pos,9,f);
18 t.replace(pos,9,f);
19 pos+=7;
20 }
21 cout<<s<<endl;
22 }
23 }
明楼

浙公网安备 33010602011771号