Getnext()
{
int i=0,j=-1;
next[i]=-1;
while(m[i]!='\0')
{
while(j!=-1&&m[i]!=m[j]) j=next[j];
if(m[++i]!=m[++j]) next[i]=j;
else next[i]=next[j];
}
}
int KMP()
{
int i=j=0;
while(z[i]!='\0')
{
if(j!=-1&&m[j]=='\0') break;
while(j!=-1&&z[i]!=m[j]) j=next[j];
++i,++j;
}
return m[i]=='\0'?i-j+1:-1;
}
{
int i=0,j=-1;
next[i]=-1;
while(m[i]!='\0')
{
while(j!=-1&&m[i]!=m[j]) j=next[j];
if(m[++i]!=m[++j]) next[i]=j;
else next[i]=next[j];
}
}
int KMP()
{
int i=j=0;
while(z[i]!='\0')
{
if(j!=-1&&m[j]=='\0') break;
while(j!=-1&&z[i]!=m[j]) j=next[j];
++i,++j;
}
return m[i]=='\0'?i-j+1:-1;
}