-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathmesaj2.cpp
56 lines (49 loc) · 1.02 KB
/
mesaj2.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
# include <bits/stdc++.h>
# define NR 1505
using namespace std;
ifstream f("mesaj2.in");
ofstream g("mesaj2.out");
int i,j,n,m,L,l,I;
short URM[130][NR], urm[130], minn[NR];
char S[NR], s[NR];
void procesare () {
for (int i=1; i<=127; ++i)
urm[i]=L+1;
for (int i=L+1; i>=1; --i) {
if (i!=L+1) urm[S[i]]=i;
for (int j=1; j<=127; ++j)
URM[j][i]=urm[j];
}
for (int i=1; i<=L; ++i)
minn[i]=L+1;
}
void update (char *word) {
int poz,VV,j;
char *p;
for (int i=1; i<=L; ++i) {
j=i-1; p=word;
while (*p && j<minn[i]) {
j=URM[(int)(*p)][j+1];
++p;
}
if (minn[i] > j) minn[i]=j;
}
}
int query () {
int sol=0;
for (int i=1; i<=L && minn[i]<=L; i=minn[i]+1)
++sol;
return sol;
}
int main ()
{
f.getline (S+1, NR); L=strlen(S+1);
procesare ();
f>>n; f.get();
for (i=1; i<=n; ++i) {
f.getline(s+1, NR);
update (s+1);
g<<query ()<<"\n";
}
return 0;
}