The Deaf Rats of Hamelin
Last updated
Last updated
int countDeafRats(const std::string &town)
{
//until we found the PP all the rats that goes to the left is deaf
//after we dound PP all that foes to the right
bool found_PP = false;
int deaf_counter = 0;
for(auto iter = town.begin(); iter != town.end(); iter++)
{
if(*iter == 'P') found_PP=true;
//going right
else if(iter[0]=='~' && iter[1]=='O') ++iter , deaf_counter+=found_PP;
//going left
else if(iter[0]=='O' && iter[1]=='~') ++iter , deaf_counter+=!found_PP;
}
return deaf_counter;
}