hihoCoder 1082然而沼跃鱼早就看穿了一切 (字符串处理)

http://hihocoder.com/problemset/problem/1082

首先将字符串全部字母变成小写,不断用find查找字符串中的Marshtomp,并把每个字符变为’#‘ ,最后统一把’#‘替换即可。

 1 #include<cstdio>
 2 #include<string>
 3 #include<iostream>
 4 using namespace std;
 5 int main()
 6 {
 7     //freopen("a.txt","r",stdin);
 8     string s,s1,s2;
 9     while(getline(cin,s))
10     {
11         s1=s;
12         for(int i=0;i<s.length();i++)
13         {
14             if(isalpha(s[i])) s[i]=tolower(s[i]);
15         }
16         int t=-1;
17         t=s.find("marshtomp");
18         //cout<<s<<endl;
19         while(t!=-1)
20         {
21             //cout<<t<<endl;
22             for(int i=t;i<t+9;i++)
23             s[i]='#';
24             t=s.find("marshtomp");
25             //cout<<s<<endl;
26         }
27         s2="";
28         for(int i=0;i<s.length();i++)
29         {
30             if(s[i]!='#') s2+=s1[i];
31             else if(s[i]=='#')
32             {
33                 s2+="fjxmlhx";
34                 i+=8;
35             }
36         }
37         cout<<s2<<endl;
38     }
39     return 0;
40 }

 

posted @ 2015-04-10 21:04  NowAndForever  阅读(220)  评论(0编辑  收藏  举报