Advertisement
GieeF

Bayer full po mojemu

Jan 16th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. void bm(string &tablica, string &wzorzec) {
  2.     int index = 0;
  3.     int s;
  4.     bool indexChanged;
  5.     while (index < tablica.size()) {
  6.         indexChanged = false;
  7.         for (int i = wzorzec.size()-1; i >= 0; i--) {
  8.             if ((index + i) >= tablica.size())
  9.                 return;
  10.             if (tablica[index + i] != wzorzec[i]) {
  11.                 for (s = 0; s < wzorzec.size(); s++) {
  12.                     if (wzorzec[s] == tablica[index + i]) {
  13.                         index += wzorzec.size() - s - 1;
  14.                         indexChanged = true;
  15.                         break;
  16.                     }
  17.                 }
  18.                 if (!indexChanged) {
  19.                     index += wzorzec.size();
  20.                     indexChanged = true;
  21.                 }
  22.             }
  23.         }
  24.         if (!indexChanged) {
  25.             cout << "TUTEJ JEST: " << index << endl;
  26.             index++;
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement