Guest User

Untitled

a guest
Jul 15th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <lvp\String.h>
  3.  
  4. int countOccurances(const String &word, String &key)
  5. /*return the number of times that key appears inside of word
  6. Pre: fill in
  7. Post: fill in*/
  8. {
  9.     int count = 0;
  10.     String myword(word);
  11.     do
  12.     {
  13.  
  14.         if (myword.find(key) != -1)
  15.         {
  16.             count ++;
  17.             myword = myword.substr(myword.find(key)+1, myword.length());
  18.         }
  19.     }while(myword.find(key) != -1);
  20.     return(count);
  21. }
  22.  
  23. int main()
  24. {
  25.  
  26.     String a("gaben boy baby bbb");
  27.     String b("b");
  28.     cout<<countOccurances(a,b);
  29.     return(0);
  30. }
Add Comment
Please, Sign In to add comment