forked from andreimargeloiu/Competitive-programming-problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
abc2.cpp
54 lines (52 loc) · 1.1 KB
/
abc2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# include <fstream>
# include <cstring>
# include <vector>
# include <algorithm>
# define mod 666013
using namespace std;
ifstream f("abc2.in");
ofstream g("abc2.out");
vector <unsigned int> h[mod];
int i,j,l,L,VV,r,ok;
unsigned int var,nr,p;
char s[10000005],ch[25];
void citeste ()
{
unsigned int nr;
f.getline(s+1, 10000005);
L=strlen(s+1);
while (f.getline(ch+1,25))
{
l=strlen(ch+1);
nr=0;
for (i=1; i<=l; ++i)
nr=nr*3+(ch[i]-'a');
//inserez
r=nr%mod; ok=1;
for (i=0; i<h[r].size(); ++i)
if (h[r][i]==nr) {ok=0; break;}
if (ok) h[r].push_back(nr);
}
}
int main ()
{
int i,r;
unsigned int var=0,p=1;
citeste();
for (i=1; i<=l; ++i)
{
var=var*3+(s[i]-'a');
p*=3;
}
p/=3; r=var%mod;
if (find(h[r].begin(), h[r].end(), var)!=h[r].end()) ++VV;
for (i=l+1; i<=L; ++i)
{
var=(var-(s[i-l]-'a')*p)*3+(s[i]-'a');
r=var%mod;
for (int j=0; j<h[r].size(); ++j)
if (h[r][j]==var) {++VV; break;}
}
g<<VV<<"\n";
return 0;
}