Guest User

Untitled

a guest
Dec 15th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5.  
  6. void naive(string p, string t){
  7.         int lengthT = t.length();
  8.         int lengthP = p.length();
  9.  
  10.         for(int i=0; i < lengthT - lengthP;)
  11.         {
  12.                 for(int k = 0; k< lengthP; k++){
  13.                         if(t[i+k] != p[k])
  14.                         {
  15.                                 i++;
  16.                                 break;
  17.                         }
  18.                         else if(k == lengthP-1)
  19.                         {
  20.                                 cout<<i<<endl;
  21.                                 i++;
  22.                         }
  23.                 }
  24.  
  25.         }
  26.  
  27. }
  28.  
  29.  
  30. int main(){
  31.  
  32. naive("ab", "aba");
  33.  
  34.  
  35. system("pause");
  36. return 0;
  37.  
  38. }
Add Comment
Please, Sign In to add comment