【hihoCoder】#1082 然而 我 早就看穿了一切

14184646038225.jpg

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

本题使用STL 的 String 就可以做出来,也可以使用暴力的方法。

#include<iostream>
#include<cstdio>
#include<map>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<bits/stdc++.h>
#include<sstream> 
#define tle ios::sync_with_stdio(0),cin.tie(0)
using namespace std;
const int maxn=10000;
typedef long long ll;
typedef pair<int,int> p;



int a[maxn];

int main()
{
	tle;
	ll i,j;
	
	string s;
	while(getline(cin,s))
	{
		int k=0;
		string t=s;
		transform(t.begin(),t.end(),t.begin(),::toupper);
		size_t found=t.find("MARSHTOMP");
		
		while(found!=string::npos)
		{
			s.replace(found,9,"fjxmlhx");
			t.replace(found,9,"fjxmlhx");
			found=t.find("MARSHTOMP",found+1);
		}
		
		
		
		cout<<s<<endl;
	}
	
	
	return 0;
}

就是使用 string find 函数,从一个大的字符串中找一个小的字符串,但是这道题目要求有点苛刻,是将字符串里面的所有的不分大小写的都换为指定的字符串,我们就将字符串都一股脑的变为 大写或者 小写,用函数时就可以 简单的查找,和替换指定一段长度的字符串。   使用到 string find 和 replace 函数。在处理过程中,我是使用一个新的 string t 变为 原串的大写,在t串中找位置,在S串 中替换字符串,所谓隔山打牛 ,但是先别急,别打到自己人了,这个换掉的字符串与原串在长度上是不一样的,所以整个串长度就会改变,你是知道的,这个替换函数 replace 就是看的是下标 从哪里开始的 ,是替换掉哪 几个 为新的串,所以在t 串中也要替换 为新的 串,才能保证不错。

讲完了 ,我早已看穿了一切 ( 我是沼泽鱼 )。(好自恋)。

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值