码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-04-10 21:51:08      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

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 }

 

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

标签:

原文地址:http://www.cnblogs.com/nowandforever/p/4415663.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!