Pagini recente » Cod sursa (job #2649909) | Cod sursa (job #1743217) | Cod sursa (job #478139) | Cod sursa (job #2349827) | Cod sursa (job #2303216)
#include <bits/stdc++.h>
using namespace std;
char s[10000005],s2[25];
int len,len2;
#define MOD 9973
struct HashInt{
vector<pair<unsigned int,int> > H[MOD];
int hashing(unsigned int n){
return n % MOD;
}
int find(unsigned int n){
int h = hashing(n);
for(auto it : H[h])
if(it.first == n)
return it.second;
return 0;
}
void update(unsigned int n){
int h = hashing(n);
for(auto &it : H[h])
if(it.first == n){
++it.second;
return ;
}
H[h].push_back({n,1});
}
void erase(unsigned int n){
int h = hashing(n);
for(auto &it : H[h])
if(it.first == n){
it = H[h].back();
H[h].pop_back();
return ;
}
}
};
HashInt Ap;
int main(){
freopen("abc2.in","r",stdin);
freopen("abc2.out","w",stdout);
cin>>s;
len=strlen(s);
bool ok=0;
int ans=0;
while(cin>>s2){
if(ok==0){
len2=strlen(s2);
for(int i=0;i<len-len2+1;++i){
unsigned int cod=0;
for(int j=i;j<i+len2;++j)
cod=cod*3+(s[j]-'a');
Ap.update(cod);
}
}
unsigned int cod=0;
for(int i=0;i<len2;++i)
cod=cod*3+(s2[i]-'a');
int nr=Ap.find(cod);
if(nr!=0){
ans+=nr;
Ap.erase(cod);
}
ok=1;
}
cout<<ans<<"\n";
return 0;
}