| B.沼跃鱼 | |||||
|
|||||
| Description | |||||
|
fjxmlhx每天都在被沼跃鱼刷屏,因此他急切的找到了你希望你写一个程序屏蔽所有句子中的沼跃鱼(“marshtomp”,不区分大小写)。 |
|||||
| 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(1)
{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;
}
|
原文地址:http://blog.csdn.net/lsgqjh/article/details/45001197