Pagini recente » Istoria paginii runda/asdaasdasd | Cod sursa (job #1560852) | Cod sursa (job #796500) | Cod sursa (job #1521464) | Cod sursa (job #2818945)
#include <fstream>
#include <set>
using namespace std;
ifstream fin("abc2.in");
ofstream fout("abc2.out");
const int base = 3;
int ans;
string s, cuv;
set <unsigned int> dictionar;
int len, s_len;
unsigned int base_pow, modh;
int main()
{
ios::sync_with_stdio(false);
fin.tie(0);
getline(fin, s);
s_len = s.size();
while(getline(fin, cuv))
{
len = cuv.size();
unsigned int myHash = 0;
for(int i = 0; i < len; i++)
myHash = myHash * base + (cuv[i] - 'a');
if(dictionar.find(myHash) == dictionar.end())
dictionar.insert(myHash);
}
base_pow = 1;
for(int i = 1; i < len; i++)
base_pow *= base;
unsigned int myHash = 0;
for(int i = 0; i < len; i++)
myHash = myHash * base + (s[i] - 'a');
if(dictionar.find(myHash) != dictionar.end())
ans++;
for(int i = len; i < s_len; i++)
{
int val = s[i - len] - 'a';
myHash = myHash - base_pow * val ;
myHash = myHash * base + (s[i] - 'a');
if(dictionar.find(myHash) != dictionar.end())
ans++;
}
fout << ans;
return 0;
}