This commit is contained in:
2024-04-18 18:38:55 +08:00
parent bfcbb1996a
commit 4f8f929242
20 changed files with 3408 additions and 0 deletions

28
ACMOJ-1507.cpp Normal file
View File

@ -0,0 +1,28 @@
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
const int kMaxN = 1e6 + 10;
char S[kMaxN], T[kMaxN];
int nxt[kMaxN];
int main() {
#ifdef local
freopen("pro.in", "r", stdin);
#endif
scanf("%s%s", S + 1, T + 1);
int len_T = strlen(T + 1);
for (int i = 2, j = 0; i <= len_T; i++) {
while (j > 0 && T[j + 1] != T[i]) j = nxt[j];
if (T[j + 1] == T[i]) j++;
nxt[i] = j;
}
int len_S = strlen(S + 1);
for (int i = 1, j = 0; i <= len_S; i++) {
while (j > 0 && (j == len_T || T[j + 1] != S[i])) j = nxt[j];
if (T[j + 1] == S[i]) j++;
if (j == len_T) printf("%d\n", i - len_T + 1);
}
for (int i = 1; i <= len_T; i++) printf("%d ", nxt[i]);
return 0;
}