Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int position, starting_point, ending_point,mx,i,r,n,lt,sum=0,len,l,t_l,ck;
- vector<int> z_value(string str)
- {
- n =str.length();
- vector<int> z(n);
- for (i = 1, l = 0, r = 0; i < n; ++i)
- {
- if (i <= r)
- z[i] = min (r - i + 1, z[i - l]);
- while (i + z[i] < n && str[z[i]] == str[i + z[i]])
- ++z[i];
- if (i + z[i] - 1 > r)
- l = i, r = i + z[i] - 1;
- }
- return z;
- }
- int main()
- {
- int t,q;
- vector<int>vec;
- string str,sub,concat;
- scanf("%d",&t);
- while(t--)
- {
- cin>>str;
- len=str.length();
- cin>>q;
- while(q--){
- cin>>sub;
- concat=sub+"$"+str;
- vec=z_value(concat);
- for(i=sub.length()+1; i<concat.length(); i++)
- {
- // cout<<vec[i]<<endl;
- if(vec[i]==sub.length())
- {
- cout<<"y"<<endl;
- ck=1;
- break;
- }
- }
- if(ck==0 && i==concat.length())
- {
- cout<<"n"<<endl;
- }
- ck=0;
- //vec.clear();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement