Pagini recente » Cod sursa (job #3351078) | Cod sursa (job #3306117) | Cod sursa (job #3349516) | Cod sursa (job #3306996) | Cod sursa (job #3319067)
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,inline")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define fast ios_base::sync_with_stdio(0);f.tie(0);g.tie(0);
#define setinf(x) memset(x,0x3f3f3f3f,sizeof(x));
#define set0(x) memset(x,0,sizeof(x));
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define vi vector<int>
#define ll long long
#define vll vector<ll>
#define pb push_back
#define fi first
#define se second
#define DD 100001
#define nl '\n'
using namespace std;
const string file="abc2";
ifstream f(file+".in");
ofstream g(file+".out");
//#define f cin
//#define g cout
string s,t;
unordered_map<ll,bool> mp;
const int mod=911382323;
ll r;
int main(){
f>>s;
int l=0;
while (f>>t) {
ll hash=0;
for (char c:t) hash=(hash*1315423911+(c-'a'))%mod;
mp[hash]=1;
if (!l) l=t.size();
}
ll p=1;
for (int i=1; i<l; ++i)
p=(p*1315423911)%mod;
ll hash=0;
for (int i=0; i<l; ++i) {
hash=(hash*1315423911+(s[i]-'a'))%mod;
}
if (mp.count(hash)) ++r;
for (int i=l; i<s.size(); ++i) {
hash=(hash-(s[i-l]-'a')*p%mod+mod)%mod;
hash=(hash*1315423911+(s[i]-'a'))%mod;
if (mp.count(hash)) ++r;
}
g<<r;
system("pause");
return 0;
}