TopCoder problem "SyllableCounter" used in SRM 248 (Division II Level One)



Problem Statement

    In the English language, a syllable can be loosely defined as a unit of uninterrupted sound. One can usually count the number of syllables in an English word by 'sounding it out'. In general, however, it is difficult to write a program to count the number of syllables in a word.



Here, we'll use the following procedure to count syllables: Each group of vowels {'A', 'E', 'I', 'O', 'U'} appearing in the word will add one syllable to the total number of syllables in the word. A group of vowels is either separated by consonants (all letters A-Z that are not vowels) or the group appears at the beginning or end of the word. So, for example, the word "HELLO" contains 2 syllables according to the above procedure due to the vowels 'E' and 'O'. The word "FOOBAR" also contains 2 syllables, even though there are 3 vowels in the word. This is because the two 'O' vowels are considered one group of vowels. Finally, the word "TELEVISION" contains 4 syllables.



Create a class SyllableCounter containing a method countSyllables which takes a String word as input. The method should return an int corresponding to the number of syllables in word according to the above algorithm.
 

Definition

    
Class:SyllableCounter
Method:countSyllables
Parameters:String
Returns:int
Method signature:int countSyllables(String word)
(be sure your method is public)
    
 

Constraints

-word will contain between 3 and 50 characters inclusive.
-word will contain only uppercase letters ('A'-'Z').
-word will contain at least one vowel and at least one consonant.
 

Examples

0)
    
"VOLUME"
Returns: 3
Note that this returns 3 because of the vowels O, U, and E. Your method should return 3 despite the fact that in spoken English, the E at the end doesn't actually create a syllable.
1)
    
"TELEVISION"
Returns: 4
2)
    
"BOOKKEEEEEEEEEEEEPER"
Returns: 3
3)
    
"SLKJSGLKAKHDGHELHDGILKLHDGOLOOOOOL"
Returns: 5

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=3524

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=7223&pm=3524

Writer:

NeverMore

Testers:

PabloGilberto , lbackstrom , brett1479

Problem categories:

String Manipulation