MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / string_match

Function string_match

code/strings/kmp.cpp:11–23  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9 if (j == 0) { pit[i] = 0; break; } } }
10 return pit; }
11int string_match(const string &s, const string &t) {
12 int n = s.size(), m = t.size();
13 int *pit = compute_pi(t);
14 for (int i = 0, j = 0; i < n; ) {
15 if (s[i] == t[j]) {
16 i++; j++;
17 if (j == m) {
18 return i - m;
19 // or j = pit[j];
20 } }
21 else if (j > 0) j = pit[j];
22 else i++; }
23 delete[] pit; return -1; }
24// vim: cc=60 ts=2 sts=2 sw=2:

Callers 1

testFunction · 0.85

Calls 2

compute_piFunction · 0.85
sizeMethod · 0.45

Tested by 1

testFunction · 0.68