Pagini recente » Cod sursa (job #2008621) | Cod sursa (job #1295425) | Cod sursa (job #842848) | Cod sursa (job #1500819) | Cod sursa (job #2771718)
#include <iostream>
#include <fstream>
#include <cstring>
#include <vector>
using namespace std;
ifstream f("abc2.in");
ofstream g("abc2.out");
const int N = 10000100;
const int MOD = 10003;
char cuv[25];
char s[N];
vector <long long> h[11000];
unsigned int n, rez;
bool exista (unsigned int has) {
unsigned int k = has % MOD;
for(int i = 0; i < h[k].size(); i ++)
if(h[k][i] == has)
return true;
return false;
}
void citire () {
f >> s;
while(f >> cuv) {
//g << cuv << ' ';
unsigned int p3 = 0;
n = strlen (cuv);
for(int i = 0; i < n; i ++)
p3 = p3 * 3 + cuv[i] - 'a' + 1;
h[p3 % MOD].push_back(p3);
//g << p3 << '\n';
}
}
int main()
{
citire ();
unsigned int p3 = 1;
for(int i = 1; i < n; i ++)
p3 *= 3;
unsigned int has = 0;
for(int i = 0; i < n; i ++) {
has = has * 3 + s[i] - 'a' + 1;
//g << s[i];
}
if(exista(has))
rez ++;
int i = n;
/* for(int i = 1; i <= 50; i ++)
if(exista(i))
//g << i << '\n';*/
while(i < strlen(s)) {
has -= (s[i - n] - 'a' + 1) * p3;
has = has * 3 + s[i] - 'a' + 1;
//g << has << ' ';
if(exista(has))
rez ++;
i ++;
}
g << rez;
//g << s;
return 0;
}