-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10679 - I Love Strings!! .cpp
57 lines (53 loc) · 1.09 KB
/
10679 - I Love Strings!! .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
// ALLAH IS ALMIGHTY //
#include <bits/stdc++.h>
using namespace std;
vector<int> lsf;
string ss, qq;
void kmp(){
int i=0, j=0;
while( i<qq.size() and j < ss.size() ){
if( qq[i]==ss[j] ){
i++;
j++;
}else{
if( j!=0 ){
j = lsf[j-1];
}else{
i++;
}
}
}
if( j==ss.size() )cout<< 'y' << endl;
else cout << 'n' << endl;
}
int main()
{
int t;
cin >> t;
while( t-- ){
cin >> qq;
int q;
cin >> q;
while( q-- ){
cin >> ss;
int len = ss.size();
lsf.assign( len,0 );
int index = 0;
for( int i=1;i<len; ){
if( ss[i]==ss[index] ){
lsf[i] = index+1;
i++;
index++;
}else{
if( index != 0 ){
index = lsf[index-1];
}else{
lsf[i] = 0;
i++;
}
}
}
kmp( );
}
}return 0;
}