#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1008611;
int n,m,t,r;
char s[N],p[N];
int ne[N];
signed main()
{
ios::sync_with_stdio(0);cin.tie(0);
cin>>n>>p+1>>m>>s+1;
//求next的过程
for(int i=2,j=0;j<=n;i++)
{
while(j&&p[i]!=p[j+1])j=ne[j];
if(p[i]==p[j+1])j++;
ne[i]=j;
}
for(int i=1,j=0;i<=m;i++)
{
while(j&&s[i]!=p[j+1])j=ne[j];
if(s[i]==p[j+1])j++;
if(j==n)
{
cout<<i-n;
j=ne[j];
}
}
return 0;
}
07-07
190
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交