0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-08 13:58:48 +00:00
Baoshuo Ren 2021-10-09 09:46:32 +08:00 committed by Baoshuo Ren
parent 4919169d97
commit 9975626619
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

26
AcWing/831/831.cpp Normal file
View File

@ -0,0 +1,26 @@
#include <bits/stdc++.h>
using namespace std;
int m, n, nxt[100005];
string p, s;
int main() {
cin >> n >> p >> m >> s;
nxt[0] = -1;
for (int i = 1, j = -1; i < n; i++) {
while (j >= 0 && p[j + 1] != p[i]) j = nxt[j];
if (p[j + 1] == p[i]) j++;
nxt[i] = j;
}
for (int i = 0, j = -1; i < m; i++) {
while (j != -1 && s[i] != p[j + 1]) j = nxt[j];
if (s[i] == p[j + 1]) j++;
if (j == n - 1) {
cout << i - j << ' ';
j = nxt[j];
}
}
cout << endl;
return 0;
}