#include <iostream>
#include <string>
size_t foo(std::string const & str, char a, char b)
{
std::string str2{a, b};
size_t res = 0;
size_t found = 0;
while((found = str.find(str2, found))!=std::string::npos)
{
++res;
found+=2;
}
return res;
}
int main() {
std::string str = "abcabcabac";
std::cout << foo(str, 'a', 'b') << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgoKc2l6ZV90IGZvbyhzdGQ6OnN0cmluZyBjb25zdCAmIHN0ciwgY2hhciBhLCBjaGFyIGIpCnsKCXN0ZDo6c3RyaW5nIHN0cjJ7YSwgYn07CglzaXplX3QgcmVzID0gMDsKCXNpemVfdCBmb3VuZCA9IDA7Cgl3aGlsZSgoZm91bmQgPSBzdHIuZmluZChzdHIyLCBmb3VuZCkpIT1zdGQ6OnN0cmluZzo6bnBvcykKCXsKCQkrK3JlczsKCQlmb3VuZCs9MjsKCX0KCXJldHVybiByZXM7Cn0KCmludCBtYWluKCkgewoJc3RkOjpzdHJpbmcgc3RyID0gImFiY2FiY2FiYWMiOwoJc3RkOjpjb3V0IDw8IGZvbyhzdHIsICdhJywgJ2InKSA8PCBzdGQ6OmVuZGw7CglyZXR1cm4gMDsKfQ==