当前的最小循环节为
len-next[len]
另附kmp代码
void next(){
next[0] = 0;
int len = 0,i=1;
while(i<n){
if(pa[i] == s[i]){
len++;
next[i] = len;
i++;
}
else{
if(len>0){
len = next[i-1];
}else{
next[i] = 0;
i++;
}
}
}
next[0] = -1;
for(int i=2;i<100;i++)
{
next[i] = next[i-1];
}
}
void solve(){
int i = 1;j = 0;
while(i<n){
if(j == n-1&&s[i]==p[j]){
cout<<"now find it"<<endl;
}
if(s[i]==p[j]){
i++;
p++;
}
else{
j = next[j];
if(j == -1){
j++;
i++;
}
}
}
}