Pagini recente » Cod sursa (job #2048899) | Cod sursa (job #2530007) | Cod sursa (job #356711) | Cod sursa (job #332587) | Cod sursa (job #2802298)
#include <bits/stdc++.h>
using namespace std;
ifstream in("abc2.in");
ofstream out("abc2.out");
const int MOD = 90911;
const int maxN = (int)1e7 + 1;
vector<unsigned int> h[MOD];
char s[maxN], c[21];
int main() {
ios_base::sync_with_stdio(false);
in.tie(NULL);
in >> s;
vector<int> v;
int l = 0;
while (in >> c) {
unsigned int x = 0;
for (int i = 0; c[i]; i++) {
x = x * 3 + c[i] - 'a';
}
h[x % MOD].push_back(x);
}
l = strlen(c);
unsigned int p = 1, x = 0;
for (int i = 0; i < l; i++) {
x = x * 3 + s[i] - 'a';
if (i > 0)
p *= 3;
}
int ans = 0;
bool found = false;
unsigned int xh = x % MOD;
for (unsigned int &y : h[xh])
if (y == x) {
found = true;
break;
}
if (found)
ans++;
for (int i = l; s[i]; i++) {
x = (x - p * (s[i - l] - 'a')) * 3 + s[i] - 'a';
found = false;
xh = x % MOD;
for (unsigned int &y : h[xh])
if (y == x) {
found = true;
break;
}
if (found)
ans++;
}
out << ans << "\n";
return 0;
}