Pagini recente » Borderou de evaluare (job #3330980) | Borderou de evaluare (job #3329609) | Borderou de evaluare (job #3356210) | Borderou de evaluare (job #3338503) | Cod sursa (job #3319082)
#include<bits/stdc++.h>
#define ll long long
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 mod1=1e9+7,mod2=1e9+9;
const int b1=131,b2=37;
int r;
int main(){
f>>s;
int l=0;
while (f>>t) {
ll h1=0,h2=0;
int n=t.size();
for (int i=0; i<n; i++) {
h1=(h1*b1+(t[i]-'a'))%mod1;
h2=(h2*b2+(t[i]-'a'))%mod2;
}
mp[(h1<<32)^h2]=1;
if (!l) l=n;
}
ll p1=1,p2=1;
ll h1=0,h2=0;
for (int i=0; i<l; ++i) {
h1=(h1*b1+(s[i]-'a'))%mod1;
h2=(h2*b2+(s[i]-'a'))%mod2;
if (i>0) {
p1=(p1*b1)%mod1;
p2=(p2*b2)%mod2;
}
}
if (mp.count((h1<<32)^h2)) ++r;
for (int i=l; i<s.size(); ++i) {
h1=(h1-(s[i-l]-'a')*p1%mod1+mod1)%mod1;
h1=(h1*b1+(s[i]-'a'))%mod1;
h2=(h2-(s[i-l]-'a')*p2%mod2+mod2)%mod2;
h2=(h2*b2+(s[i]-'a'))%mod2;
if (mp.count((h1<<32)^h2)) ++r;
}
g<<r;
// system("pause");
return 0;
}