-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUVA10679.cpp
61 lines (54 loc) · 1.03 KB
/
UVA10679.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
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include<vector>
using namespace std;
char text[100000];
char patt[1000];
void kmpPreProcessamento(int *b, string pat){
int tamp=pat.length();
int i=0;
int j=-1;
b[0]=-1;
while(i<tamp){
while(j>=0 && pat[i]!=pat[j]){
j=b[j];
}
i++;
j++;
b[i]=j;
}
b[0]=0;
}
void kmp(int *b, string text, string pat){
int i=0, j=0, tamt=text.length(), tamp=pat.length();
while(i<tamt){
if(text[i]!=pat[j]){
j=b[j];
}
j++;
i++;
if(j==tamp){
cout << "y\n";
return;
}
}
cout << "n\n";
}
int main(){
int n;
int b[1001];
scanf("%d ", &n);
for(int i=0; i<n; ++i){
cin >> text;
int q;
scanf("%d ", &q);
for(int j=0; j<q; ++j){
cin >> patt;
kmpPreProcessamento(b, patt);
kmp(b, text, patt);
}
}
return 0;
}