哈理工 第五届程序设计大赛——B.沼跃鱼

B.沼跃鱼
Time Limit: 500 MSMemory Limit: 32768 K
Total Submit: 692 (336 users)Total Accepted: 336 (305 users)Special Judge: No
Description

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

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”。

 

当时水平很差劲,不过我感觉最近 进步特别快,肯定跟最近的勤奋有关。回过头来 在做这个题目。感觉挺容易了!进步是能感觉到滴…………~!

校赛决赛被人虐惨了!唉~但现在我也会了!

方法是 用find()查找一个字符串中所有出现marshtomp的索引值,用一个数组记录。然后 再将原数组挨个元素输出,到达记录的索引值时打印

替换值,里面有很多具体细节 。

#include<iostream>
#include<string>
#include<string.h>
using namespace std;
int main()
{
	string str,ST;
	while(getline(cin,str))
	{		ST=str;
		for(int i=0;i<str.size();i++)
		{
			if(isalpha(str[i])||isspace(str[i]))
			str[i]=tolower(str[i]);
		}
	
		int k=0,cnt=0;int ls[100];
		while(str.find("marshtomp",k)!=string::npos)
		{
			ls[cnt++]=str.find("marshtomp",k);
			k=ls[cnt-1]+9;
			
			
		}
		int dic=0;
		for(int j=0;j<str.size();j++)
		{
			if(j==ls[dic])
			{
				cout<<"fjxmlhx";
				dic++;
				j+=8;
			}
			else
				cout<<ST[j];
		}
		cout<<endl;
	}
	return 0;
}


 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值