TopCoder problem "WordForm" used in SRM 173 (Division I Level One , Division II Level Two)

Problem Statement


In English, the letters A, E, I, O and U are the vowels. Y is also considered to be a vowel if it's not preceded by another vowel and is not the first letter in a word (the fact that a vowel is defined to some extent in terms of itself does not make it ambiguous). If a letter is not a vowel then it is a consonant. So in "TOY" the consonants are T and Y, and in "SYZYGY" they are S, Z and G.

A sequence of vowels will be denoted by uppercase letter 'V' and a sequence of consonants will be denoted by uppercase letter 'C'. A word can then be described as an alternating sequence of 'C' and 'V'. For instance, the word "WHEREABOUTS" has the sequence CVCVCVC, and the words "YORK" and "TOY" both have the sequence CVC. It's not permissible to have two or more consecutive 'V' or 'C' in the sequence.

Create a class WordForm containing the method getSequence which takes a String word and returns a String containing the word's sequence as described above. The word may contain both uppercase and lowercase letters, but your method should be case insensitive (see example 2).



Method signature:String getSequence(String word)
(be sure your method is public)


-word may not be an English word, or a word in any language at all, but you should still use the rules defined above. See example 3.


-word will contain between 1 and 50 characters, inclusive.
-word will only contain the characters 'A'-'Z' and 'a'-'z', both inclusive.


Returns: "CVCVCVC"
Here we have consonant-consonant-vowel-consonant-vowel-vowel-consonant-vowel-vowel-consonant-consonant. Putting together consecutive consonants and vowels gives us CVCVCVC.
Returns: "CVCVC"
Returns: "CVCV"
Mixing lowercase and uppercase does not affect the result.
Returns: "VCVCVCV"
Even though this isn't an English word, we use the rules defined in the statement to find the consonant-vowel pattern.
Returns: "C"

Problem url:

Problem stats url:




lbackstrom , brett1479

Problem categories:

String Manipulation