Pagini recente » Cod sursa (job #836188) | Cod sursa (job #536101) | Cod sursa (job #458115) | Cod sursa (job #2456432) | Cod sursa (job #1302304)
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
#define dbg(x) (cout<<#x<<" = "<<(x)<<'\n')
#ifdef HOME
const string inputFile = "input.txt";
const string outputFile = "output.txt";
#else
const string problemName = "abc2";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";
#endif
typedef long long int lld;
const int MOD = 97847;
int N, M, sol;
char S[(int)(1e7) + 1];
char W[21];
vector<lld> H[MOD + 5];
void insert(lld val) {
lld r = val % MOD;
for(auto it = H[r].begin(); it != H[r].end(); it++)
if(*it == val)
return;
H[r].push_back(val);
}
bool count(lld val) {
lld r = val % MOD;
for(auto it = H[r].begin(); it != H[r].end(); it++)
if(*it == val)
return 1;
return 0;
}
int main() {
int i;
lld s, p;
#ifndef ONLINE_JUDGE
freopen(inputFile.c_str(), "r", stdin);
freopen(outputFile.c_str(), "w", stdout);
#endif
fgets(S, (1e7) + 1, stdin);
while(fgets(W, 21, stdin)) {
if(!N)
N = strlen(W) - 1;
for(i = s = 0; i < N; i++)
s = (s * 3 + W[i] - 'a');
insert(s);
}
M = strlen(S) - 1;
for(i = s = 0, p = 1; i < N; i++) {
s = (s * 3 + S[i] - 'a');
p = (p * 3);
}
sol += count(s);
for(; i < M; i++) {
s = (s * 3 - p * (S[i - N] - 'a') + S[i] - 'a');
sol += count(s);
}
printf("%d\n", sol);
return 0;
}