NounReform
SRM 302 · 2006-05-11 · by Andrew_Lazarev
SRM 302 · 2006-05-11 · by Andrew_Lazarev · String Manipulation
Problem Statement
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:
- If the word ends in 's', 'z', 'x', 'ch' or 'sh', add 'es' to the end of the word;
- If the word ends in 'ay', 'ey', 'iy', 'oy' or 'uy', add 's' to the end of the word;
- If the word ends in 'y', but doesn't satisfy the previous rule, replace the trailing 'y' with 'ies';
- In all other cases, just add 's' to the end of the word.
You will be given a
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" }
3)
{"s", "z", "x", "ch", "sh", "ay", "ey", "iy", "oy", "uy", "y", "a", "h", "gh"}
Returns: {"ses", "zes", "xes", "ches", "shes", "ays", "eys", "iys", "oys", "uys", "ies", "as", "hs", "ghs" }
4)
{"ymmadlxopz","tsfgugctpgoj","mczpgarnliy","rqoibymsh","htbzoy","ezrrytwpybtmlsiygc"}
Returns: {"ymmadlxopzes", "tsfgugctpgojs", "mczpgarnliys", "rqoibymshes", "htbzoys", "ezrrytwpybtmlsiygcs" }
Submissions are judged against all 127 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class NounReform with a public method vector<string> makePlural(vector<string> nouns) · 127 test cases · 2 s / 256 MB per case