MCPcopy Create free account
hub / github.com/ShahjalalShohag/code-library / main

Function main

Strings/String Matching using Bitsets.cpp:7–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5vector<int> v;
6bitset<N>bs[26], oc;
7int main() {
8 int i, j, k, n, q, l, r;
9 string s, p;
10 cin >> s;
11 for(i = 0; s[i]; i++) bs[s[i] - 'a'][i] = 1;
12 cin >> q;
13 while(q--) {
14 cin >> p;
15 oc.set();
16 for(i = 0; p[i]; i++) oc &= (bs[p[i] - 'a'] >> i);
17 cout << oc.count() << endl; // number of occurences
18 int ans = N, sz = p.size();
19 int pos = oc._Find_first();
20 v.push_back(pos);
21 pos = oc._Find_next(pos);
22 while(pos < N) {
23 v.push_back(pos);
24 pos = oc._Find_next(pos);
25 }
26 for(auto x : v) cout << x << ' '; // position of occurences
27 cout << endl;
28 v.clear();
29 cin >> l >> r; // number of occurences from l to r,where l and r is 1-indexed
30 if(sz > r - l + 1) cout << 0 << endl;
31 else cout << (oc >> (l - 1)).count() - (oc >> (r - sz + 1)).count() << endl;
32 }
33 return 0;
34}

Callers

nothing calls this directly

Calls 7

_Find_firstMethod · 0.80
push_backMethod · 0.80
_Find_nextMethod · 0.80
setMethod · 0.45
countMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected