mituri

[C++] Algorytm naiwny

Aug 28th, 2015
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdio.h>
  3. #include <string>
  4. #include <cstring>
  5. #include <iostream>
  6. #include <cstdlib>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. int main(){ // ALGORYTM NAIWNY- WYSZUKIWANIE WZORCA W TEKSCIE
  12.  
  13. int i = 0;
  14. char wzorzec[] = {'a', 'l', 'a'};
  15. char tekst[] {'m', 'a', 'l', 'a', 'x'};
  16. int m = sizeof(wzorzec);
  17. int n = sizeof(tekst);
  18. cout << "m = " << m << endl << "n = " << n << "\n--------------\n";
  19.  
  20. for(i = 0; i<((n-m)+1); i++){
  21. int j = 0;
  22. while( wzorzec[j] == tekst[i+j]){
  23. cout << wzorzec[j] << endl;
  24. j++;
  25. }
  26. }
  27. system ("PAUSE");
  28. }
Advertisement
Add Comment
Please, Sign In to add comment