#include <iostream>
using namespace std;
int getIndex(const char * p,int next[])
{
if(p == NULL)
return -1;
int k = -1;
int j = 0;
next[0] = -1;
while(p[j])
{
if(k==-1||p[k]==p[j])
{
++j;
++k;
if(p[k]!=p[j])
{
next[j] = k;
}
else
{
next[j] = next[k];
}
}
else
{
k = next[k];
}
}
}
int kmpcompare(const char * srcstr,const char * deststr,int next[] )
{
if(!srcstr ||!deststr||!next)
return -1;
int i = 0;
int j = 0;
while(srcstr[i]!='\0'&&deststr[j]!='\0')
{
if(srcstr[i] == deststr[j])
{
i++;
j++;
}
else
{
if(next[j]!=-1)
{
j = next[j];
}
else
{
i++;
j=0;
}
}
}
if(deststr[j] == '\0')
{
return i-j;
}
else
{
return -1;
}
}