蒟蒻的我也就会写个KMP的板子,并不会讲
模板如下
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
char s1[1000100],s2[1000100];
int Next[1000100];
int n,m;
void Getnext()
{ int i,j,k;
i=0,j=-1;
while(i<m){
if(j==-1||s2[i]==s2[j])j++,i++,Next[i]=j;
else {
//cout<<j<<' '<<next[j]<<endl;
j=Next[j];
}
}
}
void kmp()
{ int i=0,j=0,k,ans=0;
while(i<n){
if(j==-1||s2[j]==s1[i])i++,j++;
else j=Next[j];
if(j==m){
ans++;
}
}
cout<<ans<<endl;
}
int main()
{ int i,j,k,t;
cin>>t;
while(t--){
scanf("%s",s2);
scanf("%s",s1);
n=strlen(s1);
m=strlen(s2);
Next[0]=-1;
Getnext();
kmp();
}
return 0;
}