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


思路就是先全部转换成小写字母存在另一个字符串中,
再利用strstr(s1,s2)(判断s2是否为s1的子串)找到所有marshtomp的位置,
并记录下来以便输出的时候替换之!

/*
思路就是先全部转换成小写字母存在另一个字符串中,
再利用strstr(s1,s2)(判断s2是否为s1的子串)找到所有marshtomp的位置,
并记录下来以便输出的时候替换之!
*/
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; typedef long long LL; const LL N=210; int main() { char s[N]; while(fgets(s,N,stdin)!=NULL) { char str[N]=""; int len=strlen(s)-1,i; for(i=0; i<len; i++) if(s[i]>='A'&&s[i]<='Z') str[i]=s[i]+32; else str[i]=s[i]; } int a[N]= {-1},j=0,p=0; while(1) { char *k; if(strstr(str+j,"marshtomp")) k=strstr(str+j,"marshtomp"); else break; int m=(k-&str[0])/sizeof(char); j+=9; a[p++]=m; } j=0; for(i=0; i<len; i++) { if(i==a[j]) { j++; printf("fjxmlhx"); i+=8; } else printf("%c",s[i]); } printf(" "); } return 0; }
原文地址:https://www.cnblogs.com/yu0111/p/5843374.html