TopcoderArchive
SRM21 Jun 2005
SRM 248

SyllableCounter

Problem statement, definition, constraints, and public examples.

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

  1. "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.
  2. "TELEVISION"
    Returns: 4
  3. "BOOKKEEEEEEEEEEEEPER"
    Returns: 3
  4. "SLKJSGLKAKHDGHELHDGILKLHDGOLOOOOOL"
    Returns: 5
Back to all problems