Advertisement
Kocyk

naiwny

Apr 1st, 2019
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int naiwny(int n,int m,string text,string wzorzec,int *wystepowanie)
  5. {
  6. int j=0;
  7. int i;
  8. //wystepowanie = new int[j];
  9. for(i=0;i<n-m+1;i++)
  10. {
  11. if(wzorzec == text.substr(i,m))
  12. {
  13. wystepowanie[j]=i;
  14. j++;
  15. cout<<"yy"<<endl;
  16. }
  17. }
  18.  
  19. return j;
  20.  
  21. }
  22. int main()
  23. {
  24. int j=0;
  25. string text = "ala ma kota";
  26. string wzorzec;
  27. int *wystepowanie;
  28. wystepowanie = new int[j];
  29. //cout << "Podaj tekst\n";
  30. //cin >> tekst;
  31. cout << "podaj wzorzec\n";
  32. getline(cin,wzorzec);
  33. int n=text.length();
  34. int m=wzorzec.length();
  35. j=naiwny( n, m, text, wzorzec, wystepowanie);
  36. for(int i=0; i<j; i++)
  37. {
  38. cout << wystepowanie[i] << endl;
  39. }
  40. delete[] wystepowanie;
  41. return 0;
  42.  
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement