/*
KMP算法
by KONE
*/

#include<iostream>
#include<string>
using namespace std;

int* getNxte(char p[], const int size){
    int* next = new int[size];
    next[0] = -1;        //最开头的字符串设置为-1
    int k = -1, j = 0;
    while (j < (size - 1)){
        if (k == -1 || p[j] == p[k]){
            next[++j] = ++k;
        }
        else{
            k = next[k];
        }
    }
    return next;
}