Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int endzy(const string& str)
- {
- int count = 0;
- int len = str.length();
- char ch, previous, last;
- for (int i = 1; i < len; i++) // test begins from the second char
- {
- ch = str[i];
- previous = str[i - 1];
- if (ch == ' ' || ch == ':' || ch == '-' || ch == '!' || ch == '"' || isdigit(ch))
- {
- if (previous == 'y' || previous == 'Y' || previous == 'z' || previous == 'Z')
- {
- count++;
- }
- }
- }
- last = str[len - 1];
- if (last == 'y' || last == 'Y' || last == 'z' or last == 'Z')
- {
- count++;
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement