Pagini recente » Cod sursa (job #3208580) | Cod sursa (job #463576) | Cod sursa (job #2201403) | Cod sursa (job #1269216) | Cod sursa (job #3209924)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("abc2.in");
ofstream fout("abc2.out");
int n, m;
string a, b;
unordered_map<long long, char> fr;
int main()
{
ios_base :: sync_with_stdio(false);
fin.tie(0);
fout.tie(0);
int i, cnt;
long long p, x;
fin >> a >> b;
n = a.length(); m = b.length();
p = 1;
for (i = 1; i < m; i++)
p *= 3;
x = 0;
for (i = 0; i < m; i++)
x = (x * 3 + (a[i] - 'a'));
fr[x]++;
for (i = m; i < n; i++)
{
x = (x - p * (a[i - m] - 'a'));
x = (x * 3 + (a[i] - 'a'));
fr[x]++;
}
cnt = 0;
do
{
x = 0;
for (i = 0; i < m; i++)
x = (x * 3 + (b[i] - 'a'));
cnt += fr[x];
fr[x] = 0;
}while (fin >> b);
fout << cnt << "\n";
return 0;
}