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

来源:互联网 发布:科比第一个赛季数据 编辑:程序博客网 时间:2024/04/28 05:50
B.沼跃鱼Time Limit: 500 MSMemory Limit: 32768 KTotal Submit: 692 (336 users)Total Accepted: 336 (305 users)Special Judge: NoDescription

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

Input输入包括多行。每行是一个字符串,长度不超过200。
一行的末尾与下一行的开头没有关系。Output输出包含多行,为输入按照描述中变换的结果。Sample InputThe Marshtomp has seen it all before.
marshTomp is beaten by fjxmlhx!
AmarshtompBSample OutputThe fjxmlhx has seen it all before.
fjxmlhx is beaten by fjxmlhx!
AfjxmlhxBHint

不存在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;}elsecout<<ST[j];}cout<<endl;}return 0;}


 

 

 

0 0
原创粉丝点击