Pagini recente » Cod sursa (job #2283225) | Cod sursa (job #1497006) | Cod sursa (job #2080864) | Cod sursa (job #2893492) | Cod sursa (job #2802279)
#include <bits/stdc++.h>
using namespace std;
const int MOD = 90911;
const int maxN = (int)1e7 + 1;
vector<unsigned int> h[MOD];
char s[maxN], c[21];
int main() {
freopen("abc2.in", "r", stdin);
freopen("abc2.out", "w", stdout);
scanf("%s", s);
int l = 0;
while (!feof(stdin)) {
scanf("%s", 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++;
}
printf("%d\n", ans);
return 0;
}