HDU2087 剪花布条

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2087

这道题看大佬们都用KMP做,但本萌新用string弱弱水过。。。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <stdlib.h>
 5 #include <algorithm>
 6 #include <math.h>
 7 #include <vector>
 8 #include <list>
 9 #include <map>
10 #include <set>
11 using namespace std;
12 
13 int main()
14 {
15     string str1;
16     while(cin>>str1)
17     {
18         if(str1[0]=='#') break;
19         string str2;
20         int sum=0;
21         cin>>str2;
22         for(;str1.find(str2)!=string::npos;)
23         {
24             int key=str1.find(str2);
25             sum++;
26             for(int a=key;a<key+str2.size();a++)
27             {
28                 str1.erase(str1.begin()+key);
29             }
30         }
31         cout<<sum<<endl;
32     }
33 }

 

posted @ 2017-12-20 18:23  痞子熊  阅读(123)  评论(0编辑  收藏  举报