#include #include #include using namespace std;
Inline void next (const string & t, vector & next) {// Press mode string to generate vector, next (t.size ()) Next [0] = - 1; for (int i = 1; i = 0) j = next [j]; // recursive calculation IF (t [i] == t [j 1]) Next [i] = j 1; else next [i] = 0; //}} inline string :: size_type count_kmp (Const String & S, Const String & T ) {// Using the NEXT function of the mode String T, the number of counts of counts in the primary string S is KMP algorithm // where T is non-empty, Vector Next (T.Size ()); Next (t, Next ); String :: size_type index, count = 0; for (index = 0; index