Advertisement
zeushere

whether s2 contains s1

Apr 18th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4. #include <math.h>
  5. #include <string>
  6.  
  7. using namespace std;
  8. string s1,s2;
  9. void comparsion(string,string);
  10. int counter=0;
  11. int roz=0;
  12. int where=0;
  13.  
  14. int main(){
  15. srand(time(0));
  16.  
  17. getline(cin,s1);
  18. getline(cin,s2);
  19.  
  20. comparsion(s1,s2);
  21.  
  22.  
  23. return 0;
  24. }
  25.  
  26. void comparsion(string s1,string s2)
  27. {
  28.     roz=s2.size();
  29. for(int i=0;i<=roz;i++)
  30. if(s2.find(s1,(where+i))!=string::npos)
  31. {
  32.     counter++;
  33.     where=s2.find(s1,(where+i));
  34. }
  35. cout<<"Pierwszy wyraz zawiera sie w drugim "<<counter<<" razy";
  36.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement