数组要开至少1e6
段错误+0+0+0!!!
#include<stdio.h>
#include<string.h>
#define N 1005
char p[N], q[N];
int ne[N];
int main() {
scanf("%s%s", p+1, q+1);
//puts(p+1); printf("%c\n", p[1]);
int n = strlen(p+1), m = strlen(q+1);
//printf("%d\n", m);
for(int i = 2, j = 0; i <= m; ++ i){
while(j && q[i] != q[j+1]) j = ne[j]; //非空且不匹配则回溯
if(q[i] == q[j+1]) ++ j; //匹配继续
ne[i] = j; //ne定位
}
for(int i = 1, j = 0; i <= n; ++ i){
while(j && p[i] != q[j+1]) j = ne[j];
if(p[i] == q[j+1]) ++ j;
if(j == m){
printf("%d\n", i - m + 1);
j = ne[j];
}
}
for(int i = 1; i <= m; ++ i)
{
printf("%d", ne[i]);
if(i < m) printf(" ");
}
return 0;
}