Pinkel

wzorzec naiwny

Jan 11th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. #include <time.h>
  5. using namespace std;
  6.  
  7. string tekst,wzorzec;
  8.  
  9. void generuj()
  10. {
  11. tekst = "";
  12. for(int i = 0; i < 80; i++)
  13. tekst += char(65 + (rand() % 3));
  14.  
  15. wzorzec = "";
  16. for(int i = 0; i < 3; i++)
  17. wzorzec += char(65 + (rand() % 3));
  18.  
  19. cout << "TEKST: " << tekst<< endl;
  20. cout << "WZOR : " << wzorzec<< endl;
  21. }
  22.  
  23. void szukaj()
  24. {
  25. for(int i = 0; i <= tekst.length() - wzorzec.length(); i++)
  26. for(int j = 0; tekst[i + j] == wzorzec[j]; j++)
  27. if(j == wzorzec.length() - 1)
  28. cout << i << endl;
  29. }
  30.  
  31. int main()
  32. {
  33. generuj();
  34. szukaj();
  35. }
Add Comment
Please, Sign In to add comment