You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
552 B
C++

#include <cstdio>
#include <cstring>
const int N = 400050;
char str[N];
int next[N], ans[N];
int main()
{
while (~scanf("%s", str))
{
int len = strlen(str);
next[0] = -1;
for (int i = 0, j = -1; i < len; next[++i] = ++j)
while (~j && str[i] != str[j]) j = next[j];
int idx = 0;
for (int i = len; i; i = next[i])
ans[idx++] = next[i];
idx--;
while (idx)
printf("%d ", ans[--idx]);
printf("%d\n", len);
}
return 0;
}