Pagini recente » Cod sursa (job #1206819) | Cod sursa (job #1892321) | Cod sursa (job #2059592) | Cod sursa (job #422893) | Cod sursa (job #1536957)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
vector<string> tabel[23879];
int trebuie[23879];
int main()
{
ifstream in("abc2.in");
ofstream out("abc2.out");
string s, x, d;
int total = 0, c, i;
in >> s;
while (!in.eof())
{
in >> x;
c = (7919 * (x[x.size() - 1] - 'a' + 1) + 1381 * (x[1] - 'a' + 1) + x[0] - 'a' + 1) % 23879;
tabel[c].push_back(x);
trebuie[c] = 1;
}
for (i = 0; i < 23879; i++)
{
if (trebuie[i])
{
sort(tabel[c].begin(), tabel[c].end());
}
}
d = s.substr(0, x.length());
c = (7919 * (d[d.size() - 1] - 'a' + 1) + 1381 * (d[1] - 'a' + 1) + d[0] - 'a' + 1) % 23879;
if (binary_search(tabel[c].begin(), tabel[c].end(), d)){ total++; }
for (i = x.length(); i < s.size(); i++)
{
d.push_back(s[i]);
d.erase(d.begin());
c = (7919 * (d[d.size() - 1] - 'a' + 1) + 1381 * (d[1] - 'a' + 1) + d[0] - 'a' + 1) % 23879;
if (binary_search(tabel[c].begin(), tabel[c].end(), d)){ total++; }
}
out << total;
}