-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathsearch.cpp
66 lines (60 loc) · 1.22 KB
/
search.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
55
56
57
58
59
60
61
62
63
64
65
66
# include <fstream>
# include <cstring>
# include <algorithm>
# define lmax 5005
# define nmax 105
# define alpha 28
using namespace std;
ifstream f("search.in");
ofstream g("search.out");
int i,j,n,m,lvl,VV,l,o,k,ant;
int ap[nmax][lmax][alpha]; // a[i][j][k] - pe ce pozitie apare litera k dupa pozitia j in numarul i
int st[nmax][lmax];
char ch, s[lmax];
void preprocesare ()
{
int i,j,o;
for (i=1; i<=n; ++i)
{
f.getline (s+1, lmax); l=strlen(s+1);
for (j=l; j>=1; --j)
{
k=s[j]-'a'+1;
for (o=1; o<=alpha; ++o)
ap[i][j][o]=ap[i][j+1][o];
ap[i][j][k]=j;
}
}
}
void avansare (int k)
{
int i; ++lvl;
if (lvl>lmax) return;
for (i=1; i<=n; ++i)
{
ant=st[i][lvl-1];
if ((ant==0 && lvl==1) || ant) st[i][lvl]=ap[i][ant+1][k];
}
}
void sterge ()
{
for (int i=1; i<=n; ++i)
st[i][lvl]=0;
--lvl;
}
int main ()
{
f>>n>>m; f.get();
preprocesare ();
for (o=1; o<=m; ++o)
{
f>>ch; f.get();
if (ch=='-') sterge ();
else avansare (ch-'a'+1);
VV=0;
for (i=1; i<=n; ++i)
if (st[i][lvl]) ++VV;
g<<VV<<"\n";
}
return 0;
}