AqaAsadiNames
SRM 787 · 2020-06-17 · by a.poorakhavan
Problem Statement
This problem is about a traditional way of naming the second child in a family. Aqa Asadi wants to name his second child this way.
All people in this problem have exactly two names, e.g., âYasaman Sadatâ or âMohammad Rezaâ. In this problem, we will assume that the people whose first name starts with a vowel are female and all other people are male. Note that in this problem the letter Y is considered a vowel (so the vowels are A, E, I, O, U, and Y).
You are given the
- If the gender of the first child differs from the second child, the second child will use both names of their parent with the same gender, in reversed order.
- If both children have the same gender, the second child will get its first name from the parent with the same gender as itself (i.e., girls from their mom, boys from their dad) and its second name from its older sibling.
Notes
- You should always follow the rules in the problem statement, even if the name they produce does not match the child's gender (see Example #1) or produces the same name as the first child had (see Example #4).
Constraints
- Each name (Dad, Mom, FirstChild) will contain at most 20 characters.
- Each name will have the form "First Second", with exactly one space and with exactly the first letter of each name in uppercase.
- Each name will only consist of uppercase and lowercase English letters (A-Z, a-z), and the single space between the two names.
- Dad will start with a consonant and Mom will start with a vowel (AEIOUY).
- Gender will be either "Boy" or "Girl".
"Mohammad Reza" "Yasaman Sadat" "Baqer Ali" "Boy" Returns: "Mohammad Ali"
Both children are boys, so the second child gets his first name ("Mohammad") from his father and his second name ("Ali") from his brother.
"Mohammad Reza" "Yasaman Sadat" "Baqer Ali" "Girl" Returns: "Sadat Yasaman"
The children have different genders. Thus, the second child's name is obtained by swapping her mother's two names. Note that the returned name is not a proper name for a girl, but that's what the rules produced, so that's what you should return.
"Mohammad Reza" "Yasaman Sadat" "Umi Kulsum" "Girl" Returns: "Yasaman Kulsum"
A case similar to Example #0, but this time the child gets her name by combining the names of her mother and her sister.
"Mohammad Reza" "Yasaman Sadat" "Umi Kulsum" "Boy" Returns: "Reza Mohammad"
"X Y" "Y X" "P T" "Girl" Returns: "X Y"
"Dhikrullah Ali" "Umi Kulsum" "Reza Hosseinzadeh" "Boy" Returns: "Dhikrullah Hosseinzadeh"
Note that the second child's name can sometimes have more than 20 characters.
Submissions are judged against all 42 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class AqaAsadiNames with a public method string getName(string Dad, string Mom, string FirstChild, string Gender) · 42 test cases · 2 s / 256 MB per case