HihoCoder#1082: 然而沼跃鱼早就看穿了一切

#1082 : 然而沼跃鱼早就看穿了一切

时间限制:1000ms

单点时限:1000ms

内存限制:256MB

描述

fjxmlhx每天都在被沼跃鱼刷屏,因此他急切的找到了你希望你写一个程序屏蔽所有句子中的沼跃鱼(“marshtomp”,不区分大小写)。为了使句子不缺少成分,统一换成 “fjxmlhx”

输入

输入包括多行。

每行是一个字符串,长度不超过200

一行的末尾与下一行的开头没有关系。

输出

输出包含多行,为输入按照描述中变换的结果。

样例输入

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

一开始觉得很简单,就是一个简单的字符串替换,结果居然还是WA了几次。。。无语了。

二点总结:

1.   每次替换之后要找到替换后的位置

2.   没有marshtomp的情形也要考虑到啊


代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;


string tihuan(string s,int count)
{ 
	return s.substr(0,count)+"fjxmlhx"+s.substr(count+9);
}

int main()
{
	string s;
	while(getline(cin,s))
	{
		int count;
		string result;
		int len = s.length()-8;
		result = s;
		for(count=0;count<len;count++)
		{
			if((s[count]=='m'||s[count]=='M')
				&&(s[count+1]=='a'||s[count+1]=='A')
				&&(s[count+2]=='r'||s[count+2]=='R')
				&&(s[count+3]=='s'||s[count+3]=='S')
				&&(s[count+4]=='h'||s[count+4]=='H')
				&&(s[count+5]=='t'||s[count+5]=='T')
				&&(s[count+6]=='o'||s[count+6]=='O')
				&&(s[count+7]=='m'||s[count+7]=='M')
				&&(s[count+8]=='p'||s[count+8]=='P'))
			    {
					result=tihuan(s,count);
			        s=result;
					count =count+6;
			}
		}
		cout<<result<<endl;
	}
	
	system("pause");
	return 0;
}



版权声明:本文为博主原创文章,未经博主允许不得转载。

原文地址:https://www.cnblogs.com/lightspeedsmallson/p/4785898.html