nrk009

Naive_KMP

Apr 22nd, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1.  
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
  6. #define ll long long
  7. #define ld long double
  8. #define pb push_back
  9. #define fe first
  10. #define se second
  11. #define nl "\n"
  12. #define pp pair < ll , ll >
  13. #define sz(x) (ll)x.size()
  14. #define st(x) sort(x.begin(),x.end())
  15. #define rst(x) sort(x.rbegin(), x.rend())
  16. #define all(x) x.begin(),x.end()
  17. long double pi = 3.14159265358979323;
  18.  
  19. const double EPS = 1e-12;
  20. const int N = 1e6 + 5;
  21. const int mod = 1e9 + 7;
  22.  
  23. bool naive(string &s , string &t){
  24.  
  25.       for(int i  = 0 ; i < sz(s) - sz(t) + 1 ; i++ ){
  26.           bool match = 1 ;
  27.           for(int j = 0 ; j < sz(t) ; j++){
  28.                 if(s[i+j] != t[j]){
  29.                  match = 0 ;
  30.                  break;
  31.                 }
  32.           }
  33.           if(match)return 1;
  34.  
  35.       }
  36.       return 0 ;
  37. }
  38.  
  39.  
  40. int main()
  41. {
  42.     fast;
  43.     string s , t;
  44.     cin >> s >> t ;
  45.     cout << naive(s,t);
  46.    
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.    
  69.     return 0;
  70.    
  71. }
Add Comment
Please, Sign In to add comment