提交时间:2022-02-23 13:54:26
运行 ID: 45726
#include<bits/stdc++.h> using namespace std; int n,k,len1,len2; int Next[1000001]; char s1[1000001],s2[1000001]; int main(){ scanf("%s",s1); scanf("%s",s2); len1=strlen(s1),len2=strlen(s2); int t1=0,t2; Next[0]=t2=-1; while(t1<len2) if(t2==-1 || s2[t1]==s2[t2]) Next[++t1]=++t2; else t2=Next[t2]; t1=0,t2=0; while(t1<len1) { if(t2==-1||s1[t1]==s2[t2]) t1++,t2++; else t2=Next[t2]; if(t2==len2) printf("%d\n",t1-len2+1),t2=Next[t2]; } for(int i=1;i<=len2;++i) printf("%d ",Next[i]); return 0; }