Pagini recente » Cod sursa (job #2087080) | Cod sursa (job #2043654) | Cod sursa (job #2247747) | Istoria paginii runda/rar19/clasament | Cod sursa (job #2783795)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("abc2.in");
ofstream fout("abc2.out");
const int mod = 98317;
vector<unsigned> hash_table[mod];
void Insert(unsigned x) {
int key = x % mod;
for (auto it : hash_table[key]) {
if (it == x) {
return;
}
}
hash_table[key].emplace_back(x);
}
bool check(unsigned x) {
int key = x % mod;
for (auto it : hash_table[key]) {
if (it == x) {
return true;
}
}
return false;
}
void test_case() {
string s, t;
fin >> s;
int m = 0;
while (fin >> t) {
m = t.size();
unsigned val = 0;
for (char c : t) {
val = val * 3 + (c - 'a');
}
Insert(val);
}
unsigned val = 0, pw = 1;
for (int i = 0; i < m; ++i) {
val = val * 3 + (s[i] - 'a');
pw *= 3;
}
pw /= 3;
int n = s.size(), ans = check(val);
for (int i = m; i < n; ++i) {
val -= pw * (s[i - m] - 'a');
val = val * 3 + (s[i] - 'a');
ans += check(val);
}
fout << ans << '\n';
}
int main() {
int t = 1;
for (int tc = 1; tc <= t; ++tc) {
test_case();
}
fin.close();
fout.close();
return 0;
}