Advertisement
MeehoweCK

Untitled

Oct 29th, 2020
2,077
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int znajdz_tekst(string a, string b)
  7. {
  8.     unsigned a_size = a.size();
  9.     unsigned b_size = b.size();
  10.  
  11.     bool flaga;
  12.  
  13.     for(unsigned i = 0; i <= (a_size - b_size); i++)
  14.     {
  15.         for(unsigned j = 0; j < b_size; j++)
  16.         {
  17.             flaga = true;
  18.             if(a[i + j] != b[j])
  19.             {
  20.                 flaga = false;
  21.                 break;
  22.             }
  23.         }
  24.         if(flaga)
  25.             return i;
  26.     }
  27.  
  28.     return -1;
  29. }
  30.  
  31. int main()
  32. {
  33.     cout << znajdz_tekst("ABCDEFGH", "DEFGZ")  << endl;
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement