#55. 统计以y或z结尾的单词数量
统计以y或z结尾的单词数量
Count Words Ending in 'y' or 'z'
Background
Congcong is currently learning about string processing. He encountered an interesting problem that requires counting words with a specific pattern in a text.
Problem Description
Given a string, count the number of words ending in 'y' or 'z' -- so the 'y' in "heavy" and the 'z' in "fez" count, but not the 'y' in "yellow" (not case sensitive). We'll say that a 'y' or 'z' is at the end of a word if there is not an alphabetic letter immediately following it. (Note: Character.isLetter(char) tests if a char is an alphabetic letter.)
Input Format
Input is given from standard input in the following format.
A string.
Output Format
Output is printed to standard output in the following format.
An integer, representing the count of qualifying words.
Sample
fez day
2
day fez
2
day fyyyz
2
Sample Explanation
For the sample input fez day:
- "fez" ends with 'z', and 'z' is not immediately followed by an alphabetic letter.
- "day" ends with 'y', and 'y' is not immediately followed by an alphabetic letter. Therefore, there are 2 qualifying words in total.
Constraints
Time limit: 1 second, Memory limit: 1024 KiB for each test case.