Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. int endzy(const string& str)
  2. {
  3. int count = 0;
  4. int len = str.length();
  5. char ch, previous, last;
  6.  
  7. for (int i = 1; i < len; i++) // test begins from the second char
  8. {
  9. ch = str[i];
  10. previous = str[i - 1];
  11. if (ch == ' ' || ch == ':' || ch == '-' || ch == '!' || ch == '"' || isdigit(ch))
  12. {
  13. if (previous == 'y' || previous == 'Y' || previous == 'z' || previous == 'Z')
  14. {
  15. count++;
  16. }
  17. }
  18. }
  19. last = str[len - 1];
  20.  
  21. if (last == 'y' || last == 'Y' || last == 'z' or last == 'Z')
  22. {
  23. count++;
  24. }
  25.  
  26. return count;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement