Ankit_132

C

Oct 14th, 2023
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define pb     push_back
  7.  
  8. int main()
  9. {
  10.     int n;
  11.     string t;
  12.    
  13.     cin>>n>>t;
  14.    
  15.     vector<string> s(n);
  16.     for(auto &e: s)   cin>>e;
  17.    
  18.     vector<int> ans;
  19.    
  20.     for(int i=0; i<n; i++)
  21.     {
  22.         if(abs((int)t.size() - (int)s[i].size()) > 1)
  23.             continue;
  24.            
  25.         int ch = 0;
  26.        
  27.         for(int j=0, k=0; j<s[i].size() && k<t.size(); j++, k++)
  28.         {
  29.             if(s[i][j]==t[k])       continue;
  30.            
  31.             ch++;
  32.            
  33.             if(s[i].size() > t.size())      k--;
  34.             else if(s[i].size() < t.size()) j--;
  35.         }
  36.        
  37.         if(ch == abs((int)t.size() - (int)s[i].size()) ||
  38.         (ch==1 && (int)t.size() == s[i].size()) ||
  39.         (ch==0))
  40.             ans.pb(i+1);
  41.     }    
  42.    
  43.     cout<<ans.size()<<"\n";
  44.    
  45.     for(auto e: ans)    cout<<e<<" ";
  46.     cout<<"\n";
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment