// Given a string S of length n, the KMP algorithm produces an array pnext // where pnext[i+1] is the length of the longest substring ending at S[i] which is also a prefix of S void kmp_pre(char x[], int m, int pnext[]) { int i,j; j=pnext[0]=-1; i=0; while (i=m) { return i-m; // ans++; j=pnext[j]; } } return -1; // return ans; }