#include<iostream> #include<string> usingnamespacestd; string text, pattern; int Next[10005]; int res[10005]; int palen, txtlen; int p; voidInit() { Next[1] = 0; int k = 0;
for (int i = 1; i < palen; i++) { while ((k > 0) and (pattern[k] != pattern[i])) { k = Next[k]; }
if (pattern[k] == pattern[i]) { k++; }
Next[i] = k; } }
voidSee() { for (int i = 0; i < txtlen - palen + 1; i++) { p = 0;
for (int j = 0; j < palen; j++) { if (text[i + j] == pattern[j]) { p++; } else { i = i + j - Next[j + 1] - 1; break; } }
if (p == palen) { cout << i + 1 << endl; i = i + palen - Next[palen] - 1; } } }