Pagini recente » Cod sursa (job #2791978) | Cod sursa (job #298597) | Cod sursa (job #1874050) | Cod sursa (job #1422362) | Cod sursa (job #3219041)
#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define ll long long
//#define int long long
using namespace std;
const string TASK("abc2");
ifstream fin(TASK + ".in");
ofstream fout(TASK + ".out");
#define cin fin
#define cout fout
const int N = 2009, P = 3, M = 1e9 + 123;
char s[10000009], t[21];
unordered_map<ll, bool> mp;
signed main()
{
cin >> s;
int n = 0;
for(ll hsh = 0; cin >> t; hsh = 0)
{
if(!n)n = strlen(t);
for(int i = 0; i < n; ++i)
hsh = hsh * P + t[i] - 'a';
mp[hsh] = true;
}
ll pt = 1, hsh = 0;
for(int i = 1; i <= n; ++i)pt = pt * P;
int ans = 0;
int sz = strlen(s);
for(int i = 0; i < sz; ++i)
{
hsh = hsh * P + s[i] - 'a';
if(i >= n)hsh = hsh - (s[i - n] - 'a') * pt;
if(i + 1 < n)continue;
if(mp[hsh])ans ++;
}
cout << ans << '\n';
return 0;
}