Pagini recente » Cod sursa (job #229748) | Cod sursa (job #1049940) | Cod sursa (job #867870) | Cod sursa (job #226779) | Cod sursa (job #2106869)
#include <bits/stdc++.h>
using namespace std;
const int LenMax = 10000005;
const int WordLenMax = 30;
char Text[LenMax], Word[WordLenMax];
int TextSize, WordSize;
const int Base = 3;
map <unsigned int, bool> HashTable;
int main()
{
ifstream cin("abc2.in");
ofstream cout("abc2.out");
cin >> Text;
TextSize = strlen(Text);
while(cin >> Word)
{
WordSize = strlen(Word);
unsigned int hashCode = 0;
for(int i = 0; i < WordSize; i++)
hashCode = hashCode * Base + Word[i] - 'a';
HashTable[hashCode] = 1;
}
if(TextSize < WordSize)
{
cout << "0\n";
return 0;
}
unsigned int Power = 1;
for(int i = 1; i < WordSize; i++)
Power *= Base;
unsigned int hashCode = 0;
for(int i = 0; i < WordSize; i++)
hashCode = hashCode * Base + Text[i] - 'a';
int answer = 0;
if(HashTable.find(hashCode) != HashTable.end())
answer++;
for(int i = WordSize; i < TextSize; i++)
{
hashCode -= (Text[i - WordSize] - 'a') * Power;
hashCode = hashCode * Base + Text[i] - 'a';
if(HashTable.find(hashCode) != HashTable.end())
answer++;
}
cout << answer << "\n";
return 0;
}