B.沼跃鱼 | |||||
| |||||
Description | |||||
fjxmlhx每天都在被沼跃鱼刷屏,因此他急切的找到了你希望你写一个程序屏蔽所有句子中的沼跃鱼(“marshtomp”,不区分大小写)。 | |||||
Input | |||||
输入包括多行。每行是一个字符串,长度不超过200。 一行的末尾与下一行的开头没有关系。 | |||||
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 | |||||
Hint | |||||
不存在mar shto mp这种用空格分开的情况。 有可能一个句子中有两个以上“marshtomp”。 |
Submit | Message |
#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
using namespace std;
int main()
{
char c[250];
int i,f,f1,j,flag;
string buf,a="marshtomp",b="fjxmlhx",e,h;
while(cin.getline(c,250))
{
flag=0;
string e(&c[0],&c[strlen(c)]);
stringstream ss(e);
while(ss>>buf)
{
h=buf;
for(i=0;i<h.length();i++)
{
h[i]=tolower(h[i]);
}
if(h.find(a,0)!=-1)
{
f=h.find(a,0);
f1=f+9;
if(flag==0)
{
for(j=0;j<f;j++)
{
cout<<buf[j];
}
cout<<b;
for(j=f1;j<h.length();j++)
{
cout<<buf[j];
}
flag++;
}
else
{
cout<<" ";
for(j=0;j<f;j++)
{
cout<<buf[j];
}
cout<<b;
for(j=f1;j<h.length();j++)
{
cout<<buf[j];
}
}
}
else
{
if(flag==0)
{
cout<<buf;
flag++;
}
else
{
cout<<" "<<buf;
}
}
}
cout<<endl;
}
}
不知道为什么错了!发一个一次AC代码
#include<string>
#include<sstream>
#include<iostream>
using namespace std;
int main()
{
char c[250],a[250];
int stl,i,j;
while(cin.getline(c,250))
{
strcpy(a,c);
//puts(d);
stl=strlen(c);
for(i=0;i<stl;i++)
{
a[i]=tolower(a[i]);
}
for(i=0;i<stl;i++)
{
if(a[i]=='m'&&a[i+1]=='a'&&a[i+2]=='r'&&a[i+3]=='s'&&a[i+4]=='h'&&a[i+5]=='t'&&a[i+6]=='o'&&a[i+7]=='m'&&a[i+8]=='p')
{
printf("fjxmlhx");i=i+8;
}
else
{
printf("%c",c[i]);
}
}
printf("\n");
}
}