code.cpp 861 B

1234567891011121314151617181920212223242526272829
  1. // checks for capital and lower case s
  2. bool validS(char k){
  3. return 's' == k || 'S' == k;
  4. }
  5. bool isParselTongue(std::string s) {
  6. //"Steve likes to eat pancakes"
  7. // solve for capitals. solve for hisses. solve for hissses.
  8. // if no s is found, return true
  9. if(std::string::npos == s.find('s')){return true;}
  10. for(int i = 0;i<s.size();i++){
  11. if (validS(s[i])) {
  12. // only one s was found, next character was not s. immediately fail.
  13. if(!validS(s[i+1])){return false;}
  14. // if we found 2 consecutive s, do not check the second one.
  15. else{
  16. // find all consecutive s
  17. for(int j= i;j<s.size();j++){
  18. // an s was found, skip it
  19. if(validS(s[j])){i++;}
  20. // no s found, start checking again
  21. else {break;}
  22. }
  23. }
  24. }
  25. }// end of i loop
  26. // if we have gotten this far, the string is ok
  27. return true;
  28. }// end of function