Title Link: Poj 2406 Power Strings
Test instructions
Give you a string that lets you find out the maximum number of loops for this string, and the minimum loop.
Exercises
Using KMP's NXT array, l=j-nxt[j], is the smallest follow-up link to the prefix J.
1#include <cstdio>2#include <algorithm>3#include <cstring>4 #defineF (I,A,B) for (int i= (a); i<= (b); ++i)5 using namespacestd;6 7 voidKmp_pre (Char*x,intMint*NXT) {8 inti,j;9j=nxt[0]=-1, i=0;Ten while(i<m) { One while(-1!=J&&X[I]!=X[J]) j=Nxt[j]; Anxt[++i]=++J; - } - } the - Const intn=1e6+7; - CharS[n]; - intNxt[n],n; + - intMain () { + while(~SCANF ("%s", s)) A { at if(*s=='.') Break; -n=strlen (s); - Kmp_pre (S,N,NXT); - intans=1; - if(n% (n-nxt[n]) = =0) ans=n/(nnxt[n]); -printf"%d\n", ans); in } - return 0; to}
View Code
POJ 2406 Power Strings (KMP NXT Array for Minimum loop section)