Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using std::string;
- bool checkSub(string sub, string check, int check_start);
- int main(void) {
- int count = 0;
- string check = "hello my name is john";
- string sub = "oh";
- for(int i = 0; i < check.length(); i++) {
- if(check[i] == sub[0]) {
- if(checkSub(sub, check, i))
- count++;
- }
- }
- std::cout << count << std::endl;
- return 0;
- }
- bool checkSub(string sub, string check, int check_start) {
- if(sub.length() > check.length()-check_start)
- return false;
- for(int i = 0; i < sub.length(); i++) {
- if(sub[i] != check[check_start+i])
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement