题意:
求文本串最多可以分成几个模式串。
分析:
KMP
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define N 1010
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
char T[N],P[N];
int f[N];
void getnext(int n){
int i=,j=-;
f[]=-;
while(i<n){
if(j==-||P[i]==P[j]){
i++;
j++;
f[i]=j;
}
else j=f[j];
}
}
void KMP(){
int n=strlen(T);
int m=strlen(P);
getnext(m);
int num=,i=,j=;
while(i<n){
if(T[i]==P[j]||j==-){
i++;
j++;
}
else j=f[j];
if(j==m){
num++;
j=;//包含一个模式串,j置0继续向后找
}
}
printf("%d\n",num);
}
int main()
{
while(~scanf("%s",T)){
if(T[]=='#')break;
scanf("%s",P);
KMP();
}
return ;
}