Pagini recente » Cod sursa (job #3352156) | Cod sursa (job #3338444) | Cod sursa (job #3331918) | Cod sursa (job #3331939) | Cod sursa (job #3321954)
#include <fstream>
#include <unordered_map>
#include <cstring>
#include <cmath>
using namespace std;
ifstream fin("abc2.in");
ofstream fout("abc2.out");
///a = 0, b = 1, c = 2
unordered_map <long long, int> M;
unordered_map <long long, int> M2;
#define N 10000001
string text, cuv;
long long transforma(string s)
{
long long nr = 0;
for(int i = 0; i < s.size(); i++)
nr = nr * 3 + (s[i] - 'a');
return nr;
}
int main()
{
fin >> text;
while(fin >> cuv)
{
long long nr = transforma(cuv);
if(M.find(nr) == M.end())
M[nr] = 1;
}
int lg = cuv.size();
string s = text.substr(0, lg);
long long n = transforma(s);
if(M.find(n) != M.end())
if(M2.find(n) == M2.end())
M2[n] = 1;
else M2[n]++;
long long p = pow(3, lg - 1);
for(int i = lg; i < text.size(); i++)
{
n -= p * (text[i - lg] - 'a');
n *= 3;
n += text[i] - 'a';
if(M.find(n) != M.end())
if(M2.find(n) == M2.end())
M2[n] = 1;
else M2[n]++;
}
int cnt = 0;
for(auto per : M2)
cnt += per.second;
fout << cnt;
return 0;
}