include
include
using std::cin;
using std::cout;
using std::endl;
using std::string;
/求next/
void NEXT(string test, int *next, int n)
{
next[0] = -1;
int k = -1;
int j = 0;
while (j < n - 1)
{
if (k == -1 || test[j] == test[k])
{
++j;
++k;
if (test[j] == test[k])
next[j] = next[k];
else
next[j] = k;
}
else
k = next[k];
}
for (int i = 0; i < n; i++)
cout << next[i] << endl;
}
int KMP(string str, int slen, string ptr, int tlen)
{
int *next = new int[tlen];
NEXT(ptr, next, tlen);
int k = -1;
int j = 0;
while (j < slen&& k