Code:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 1000010
int f[N],n,ans,len1,len2; char str1[N],str2[N];
int main()
{
	scanf("%s%s",str2+1,str1+1),len1=strlen(str1+1),len2=strlen(str2+1);
	for(int i=1,j=0;i<len1;f[++i]=j)
	{
		while(j&&str1[i+1]!=str1[j+1]) j=f[j];
		if(str1[i+1]==str1[j+1]) j++;
	}
	for(int i=1,j=0;i<=len2;i++)
	{
		while(j&&str2[i]!=str1[j+1]) j=f[j];
		if(str2[i]==str1[j+1]) j++;
		if(j==len1) printf("%d\n",i-len1+1),j=f[j];
	}
}

  

相关文章:

  • 2021-12-24
  • 2022-12-23
  • 2022-01-18
  • 2021-07-23
猜你喜欢
  • 2022-12-23
  • 2021-08-13
  • 2021-06-12
  • 2022-12-23
  • 2021-06-05
  • 2021-12-12
相关资源
相似解决方案