Cod sursa(job #1536968)

Utilizator LegionHagiu Stefan Legion Data 26 noiembrie 2015 20:06:21
Problema Abc2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
vector<string> tabel[700];
int trebuie[700];
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 = (11 * (x[x.size() - 1] - 'a' + 1) + 43 * (x[1] - 'a' + 1) + x[0] - 'a' +1+ 151 * (x[x.size() - 2] - 'a' + 1)) % 700;
		tabel[c].push_back(x);
		trebuie[c] = 1;
	}
	for (i = 0; i < 500; i++)
	{
		if (trebuie[i])
		{
			sort(tabel[i].begin(), tabel[i].end());
		}
	}
	d = s.substr(0, x.length());
	c = (11 * (d[d.size() - 1] - 'a' + 1) + 43 * (d[1] - 'a' + 1) + d[0] - 'a'+1 + 151 * ( d[d.size() - 2] - 'a' + 1)) % 700;
	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 = (11 * (d[d.size() - 1] - 'a' + 1) + 43 * (d[1] - 'a' + 1) + d[0] - 'a'+1 + 151 * ( d[d.size() - 2] - 'a' + 1)) % 700;
		if (binary_search(tabel[c].begin(), tabel[c].end(), d))
		{ 
			total++; 
		}
	}
	out << total;
}