K - The Marshtomp has seen it all before HihoCoder - 1082

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

#include<iostream>
#include<string.h>
using namespace std;
char s[10005];
char st[100]="marshtomp";
char st1[100]="fjxmlhx$$";
char c[100];
int main()
{ 
	int i,j,pos,p,q;
	while(gets(s))
	{
	int n=strlen(s);
	for(i=0;i<n;i++)
	{
		if(s[i]=='m'||s[i]=='M')
		{
			memset(c,0,sizeof(c));
			pos=i;
			q=0;
			for(j=pos;j<=pos+8;j++)
			{
				if(s[j]>='A'&&s[j]<='Z')
				{
					c[q]=s[j]+32;
					q++;
				}
				else
				{
					c[q]=s[j];
					q++;
				}
			}
			p=0;
			if(strncmp(c,st,9)==0)
			{
				for(i=pos;i<=pos+8;i++)
				{
					s[i]=st1[p];
					p++;
				}
			}
		}
	}
	for(i=0;i<n;i++)
	{
		if(s[i]!='$')
		cout<<s[i];
	}
	cout<<endl;
	}
	return 0;
 } 

猜你喜欢

转载自blog.csdn.net/qq_41333844/article/details/80587575