Pagini recente » Cod sursa (job #2779050) | Cod sursa (job #2549772) | Cod sursa (job #2972811) | Cod sursa (job #3147670) | Cod sursa (job #2297077)
#include <fstream>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
ifstream in("abc2.in");
ofstream out("abc2.out");
int cnt, n, len, ans;
string ch;
string cuv;
unordered_set<long long> hashes;
long long h, put3 = 1;
int main()
{
ios_base::sync_with_stdio(false);
getline(in, ch);
while(!in.eof())
{
getline(in, cuv);
n = max(n, (int)cuv.length());
h = 0;
for(int i = 0; i < n; i++)
h = h * 3 + cuv[i] - 'a';
hashes.insert(h);
}
len = ch.length();
h = 0;
for(int i = 0; i < n; i++)
{
h = h * 3 + ch[i] - 'a';
put3 *= 3;
}
put3 /= 3;
for(int i = n; i < len; i++)
{
ans += hashes.count(h);
while(h >= put3)
h -= put3;
h = h * 3 + ch[i] - 'a';
}
ans += hashes.count(h);
out << ans;
return 0;
}