<div style="box-sizing: border-box; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 20px;"><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 10px;">fjxmlhx每天都在被沼跃鱼刷屏,因此他急切的找到了你希望你写一个程序屏蔽所有句子中的沼跃鱼(“marshtomp”,不区分大小写)。为了使句子不缺少成分,统一换成 “fjxmlhx” 。</p><h3 style="box-sizing: border-box; font-weight: 500; line-height: 1.1; color: inherit; margin-top: 20px; margin-bottom: 10px; font-size: 24px;">输入</h3><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 10px;">输入包括多行。</p><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 10px;">每行是一个字符串,长度不超过200。</p><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 10px;">一行的末尾与下一行的开头没有关系。</p><h3 style="box-sizing: border-box; font-weight: 500; line-height: 1.1; color: inherit; margin-top: 20px; margin-bottom: 10px; font-size: 24px;">输出</h3><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 10px;">输出包含多行,为输入按照描述中变换的结果。</p></div><dt style="box-sizing: border-box; line-height: 1.42857143; font-weight: bold; font-size: 18px; margin: 10px 0px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">样例输入</dt><dd style="box-sizing: border-box; line-height: 20px; margin: 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px;"><pre style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; white-space: pre-wrap; padding: 9.5px; margin-top: 0px; margin-bottom: 10px; line-height: 1.42857143; word-break: break-all; word-wrap: break-word; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px;">The Marshtomp has seen it all before.
marshTomp is beaten by fjxmlhx!
AmarshtompB
样例输出
The fjxmlhx has seen it all before.
fjxmlhx is beaten by fjxmlhx!
AfjxmlhxB
#include <string>
#include <iostream>
#include <vector>
using namespace std;
bool isPattern(const string &str1,const string &str2)
{
string s1(str1);
string s2(str2);
if(s1.length()==s2.length())
{
int flag=1;
for(auto &w:s1)
w=toupper(w);
for(auto &w:s2)
w=toupper(w);
for(int i=0;i<s1.length();i++)
{
if(s1[i]!=s2[i])
flag=0;
}
if(flag)
return true;
else
return false;
}
else
return false;
}
string strRpl(const string &s1,const string &s2,const string &s3)
{
string ret;
string str;
int n1=s1.length();
int n2=s2.length();
int i=0;
while(i<n1)
{
str=s1.substr(i,n2);
if(isPattern(str,s2))
{
ret+=s3;
i=i+n2;
}
else
{
ret+=s1[i];
i++;
}
}
return ret;
}
int main()
{
string line;
string ret;
vector<string> results;
while(getline(cin,line))
{
ret=strRpl(line,"marshtomp","fjxmlhx");
results.push_back(ret);
}
for(auto v:results)
cout<<v<<endl;
}