Advertisement
MeehoweCK

Untitled

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