Pagini recente » Cod sursa (job #1748872) | Istoria paginii runda/redsnow_1 | Monitorul de evaluare | Rating Razvan Gabriel (Razvan86) | Cod sursa (job #1761346)
#include <bits/stdc++.h>
const int NMAX = 1e9;
const int MOD = 70853;
using namespace std;
ifstream fin("abc2.in");
ofstream fout("abc2.out");
vector < int > H[MOD];
string S,s;
bitset < NMAX > F;
int P[20];
int Hash(const int &x){
int r = 0;
for(int i = 0; i < H[x % NMAX].size(); i++){
if(H[x % NMAX][i] == x)
r++;
}
return r;
}
int Tr(const char &x){
return x - 'a' + 1;
}
int main()
{
ios :: sync_with_stdio(false);
fin.tie(NULL);
for(int i = 0; i < 20 ; i++)
P[i] = pow(3,i);
fin >> S >> s;
int n = S.size(), m = s.size(),a, r = 0;
for(int i = 0; i <= n - m; i++){
a = 0;
for(int j = 0,k = i; j < m; j++,k++){
a += Tr(S[k]) * P[j];
}
H[a % MOD].push_back(a);
}
do{
a = 0;
for(int i = 0; i < m; i++){
a += Tr(s[i]) * P[i];
}
if(F[a] == 0){
r += Hash(a);
F[a] = 1;
}
s.clear();
}while(fin >> s);
fout << r;
return 0;
}