Topic Transfer: POJ-2752
Idea: is to find the current string of the maximum of the same prefix suffix, find a after, so that the same prefix suffix is the current string, and then loop call, note because the KMP next function in the maximum of the same prefix suffix does not contain itself, so each time to more output the original string itself length
AC Code:
#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int maxn = 1000005; Char s[maxn];int next[maxn];int ans[maxn];int len;void get_next (char *s) {next[0] = -1;int i = 0, j = -1;while (i < len) {if (j = =-1 | | s[i] = = S[j]) next[++ i] = + + J;else j = next[j];}} int main () {while (scanf ("%s", s)! = EOF) {int tot = 0;len = strlen (s); Get_next (s); int tmp = NEXT[LEN];IF (tmp! = 0) {ans[to T + +] = tmp;} while (Next[tmp] > 0) {tmp = Next[tmp];ans[tot + +] = tmp;} for (int i = tot-1; I >= 0; I-) {printf ("%d", Ans[i]);} printf ("%d\n", Len);} return 0;}
Poj-2752-seek the Name, Seek the Fame (kmp-print prefix suffix length)