Pagini recente » Cod sursa (job #3147446) | Cod sursa (job #2901238) | Istoria paginii runda/viata_periculoasa_pe_infoarena2 | Cod sursa (job #3147703) | Cod sursa (job #2297075)
#include <fstream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
ifstream in("abc2.in");
ofstream out("abc2.out");
int cnt, n, len, ans;
string ch;
string cuv;
unordered_map<long long, vector<string>> Hash;
char temp[10000001];
char *tmp2;
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';
Hash[h].push_back(cuv);
}
len = ch.length();
h = 0;
for(int i = 0; i < n; i++)
{
temp[i] = ch[i];
h = h * 3 + ch[i] - 'a';
put3 *= 3;
}
tmp2 = temp;
put3 /= 3;
for(int i = n; i < len; i++)
{
string str(tmp2);
vector<string> tmpVec = Hash[h];
for(int j = 0; j < tmpVec.size(); j++)
if(tmpVec[j] == str)
{
ans++;
break;
}
tmp2++;
temp[i] = ch[i];
h = h % put3;
h = h * 3 + ch[i] - 'a';
}
string str(tmp2);
vector<string> tmpVec = Hash[h];
for(int j = 0; j < tmpVec.size(); j++)
if(tmpVec[j] == str)
{
ans++;
break;
}
out << ans;
return 0;
}