这波,这波是上手进行康复训练
char s[MAXN], s1[MAXN];
int nex[MAXN];
void make_next() {
int i = 0, j = -1;
int len = strlen(s);
nex[0] = -1;
while(i < len) {
if(j == -1 || s[i] == s[j]) {
i++;
j++;
nex[i] = j;
}
else j = nex[j];
}
}
void out_next() {
int len = strlen(s);
for(int i = 0; i < len; i++) {
cout << nex[i] << endl;
}
}
void kmp() {
make_next();
int i = 0, j = 0;
int len = strlen(s1), lens = strlen(s);
while(i < len) {
if(j == -1 || s[j] == s1[i]) {
j++;
i++;
}
else j = nex[j];
if(j == lens) {
cout << i << endl;
break;
}
}
}
int main() {
cin >> s;
cin >> s1;
kmp();
return 0;
}