daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Mar 25th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int position, starting_point, ending_point,mx,i,r,n,lt,sum=0,len,l,t_l,ck;
  4. vector<int> z_value(string str)
  5. {
  6.     n =str.length();
  7.     vector<int> z(n);
  8.     for (i = 1, l = 0, r = 0; i < n; ++i)
  9.     {
  10.         if (i <= r)
  11.             z[i] = min (r - i + 1, z[i - l]);
  12.         while (i + z[i] < n && str[z[i]] == str[i + z[i]])
  13.             ++z[i];
  14.         if (i + z[i] - 1 > r)
  15.             l = i, r = i + z[i] - 1;
  16.     }
  17.     return z;
  18.  
  19. }
  20. int main()
  21. {
  22.     int t,q;
  23.     vector<int>vec;
  24.     string str,sub,concat;
  25.    scanf("%d",&t);
  26.     while(t--)
  27.     {
  28.         cin>>str;
  29.         len=str.length();
  30.         cin>>q;
  31.         while(q--){
  32.         cin>>sub;
  33.         concat=sub+"$"+str;
  34.            vec=z_value(concat);
  35.             for(i=sub.length()+1; i<concat.length(); i++)
  36.             {
  37.                // cout<<vec[i]<<endl;
  38.                 if(vec[i]==sub.length())
  39.                 {
  40.                     cout<<"y"<<endl;
  41.                     ck=1;
  42.                     break;
  43.                 }
  44.             }
  45.             if(ck==0 && i==concat.length())
  46.             {
  47.                 cout<<"n"<<endl;
  48.             }
  49.             ck=0;
  50.             //vec.clear();
  51.         }
  52.     }
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top