TopCoder problem "NounReform" used in SRM 302 (Division II Level One)



Problem Statement

    

In the English language, the plural form of a noun is created according to many difficult rules, but for the most part, a noun can be transformed into its plural form using four simple rules. These rules are:

  1. If the word ends in 's', 'z', 'x', 'ch' or 'sh', add 'es' to the end of the word;
  2. If the word ends in 'ay', 'ey', 'iy', 'oy' or 'uy', add 's' to the end of the word;
  3. If the word ends in 'y', but doesn't satisfy the previous rule, replace the trailing 'y' with 'ies';
  4. In all other cases, just add 's' to the end of the word.

You will be given a String[] nouns. Transform each element of nouns into its plural form using the rules above and return the resulting String[].

 

Definition

    
Class:NounReform
Method:makePlural
Parameters:String[]
Returns:String[]
Method signature:String[] makePlural(String[] nouns)
(be sure your method is public)
    
 

Constraints

-nouns will contain between 1 and 50 elements, inclusive.
-Each element of nouns will contain between 1 and 20 characters, inclusive.
-Each element of nouns will consist of only lower-case letters ('a'-'z').
 

Examples

0)
    
{"box", "church", "elephant", "stereo"}
Returns: {"boxes", "churches", "elephants", "stereos" }
1)
    
{"tray", "key", "enemy", "baby"}
Returns: {"trays", "keys", "enemies", "babies" }
2)
    
{"a", "s", "oy", "y", "yy"}
Returns: {"as", "ses", "oys", "ies", "yies" }

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=9823&pm=6375

Writer:

Andrew_Lazarev

Testers:

PabloGilberto , brett1479 , legakis , Olexiy

Problem categories:

String Manipulation