TopCoder problem "NiceOrUgly" used in SRM 327 (Division I Level One , Division II Level Three)



Problem Statement

    A string is called ugly if it has 3 vowels in a row, or 5 consonants in a row, or both. A string is called nice if it is not ugly. You are given a string s, consisting of uppercase letters ('A'-'Z') and question marks ('?'). Return "UGLY" if the string is definitely ugly (that means you cannot substitute letters for question marks so that the string becomes nice), "NICE" if the string is definitely nice, and "42" if it can be either ugly or nice (quotes for clarity only).
 

Definition

    
Class:NiceOrUgly
Method:describe
Parameters:String
Returns:String
Method signature:String describe(String s)
(be sure your method is public)
    
 

Notes

-The letters 'A', 'E', 'I', 'O', 'U' are vowels, and all others are consonants.
 

Constraints

-s will contain between 1 and 50 characters, inclusive.
-Each character in s will be either '?', or an uppercase letter ('A'-'Z').
 

Examples

0)
    
"HELLOWORLD"
Returns: "NICE"
1)
    
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Returns: "UGLY"
Apparently the English alphabet has 5 consonants in a row.
2)
    
"HELLOW?RLD"
Returns: "42"
"HELLOWORLD" is nice, "HELLOWZRLD" is ugly.
3)
    
"H??LOWOR??"
Returns: "NICE"
You just can't make it ugly.
4)
    
"EE?FFFF"
Returns: "UGLY"
Whatever you put there, it becomes ugly.

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10007&pm=6871

Writer:

Petr

Testers:

PabloGilberto , brett1479 , Olexiy , ged

Problem categories:

Dynamic Programming