intkmp(string str, string pattern){ // resolve the NEXT array int* next = newint[pattern.size() + 1]; next[0] = -1; calNext(pattern, 1, next);
// pattern match int m = 0; int i = 0, j = 0; for (; i < str.size();) { if (j == -1) { i++; j = 0; continue; } int k = j; for (; k < pattern.size(); k++) if (str[i + k - j] != pattern[k]) break; if (k == pattern.size()) m++; i += k - j; j = next[k]; }
return m; }
intmain(){ int N = 0; cin >> N; for (int i = 0; i < N; i++) { string pattern, str; cin >> pattern >> str;