Pagini recente » Cod sursa (job #201106) | Cod sursa (job #2442479) | Cod sursa (job #1427069) | Cod sursa (job #2317059) | Cod sursa (job #2802284)
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
using namespace std;
const int MOD = 90907;
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);
unsigned int l = 0;
while (!feof(stdin)) {
scanf("%s", c);
unsigned int x = 0;
for (unsigned int i = 0; c[i]; i++) {
x = x * 3 + c[i] - 'a';
}
if (find(h[x % MOD].begin(), h[x % MOD].end(), x) != h[x % MOD].end())
continue;
h[x % MOD].push_back(x);
}
l = strlen(c);
unsigned int p = 1, x = 0;
for (unsigned int i = 0; i < l; i++) {
x = x * 3 + s[i] - 'a';
if (i > 0)
p *= 3;
}
unsigned 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 (unsigned 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;
}