TopCoder problem "Genetics" used in TCO04 Qual 4 (Division I Level One)



Problem Statement

    In genetics, most large animals have two copies of every gene - one from each parent. In the simplest genetic model, each of the genes takes on one of two forms, usually represented by an uppercase and lowercase letter of the same value ('A' and 'a', for example). The pair of genes typically contributes to the external qualities of the animal in one of two ways. If both genes are uppercase, they contribute in one way, while if both genes are lowercase, they contribute in another way. If one gene is uppercase and the other is lowercase, then the pair acts like either a pair of uppercase genes or a pair of lowercase genes depending on whether the gene represented by the uppercase letter is dominant or recessive, respectively.



In this problem, you will be given two Strings, g1 and g2, each representing the genes from one parent. Hence, two characters from g1 and g2 with the same index make up a single gene. You will also be given a String, dom, telling you whether an uppercase gene is dominant or recessive, represented by 'D' and 'R', respectively (characters of dom correspond to characters of g1 and g2 with the same index). You are to return a String representing the external qualities of each pair of genes. If a pair of genes has the quality of two uppercase letters, the return should have an uppercase letter, and if not the return should have a lowercase letter. In either case, each letter should have the same value as the corresponding letters of g1 and g2.
 

Definition

    
Class:Genetics
Method:getOffspring
Parameters:String, String, String
Returns:String
Method signature:String getOffspring(String g1, String g2, String dom)
(be sure your method is public)
    
 

Constraints

-g1 and g2 will contain only letters ('a'-'z' and 'A'-'Z').
-dom will contain only 'D's and 'R's.
-dom, g1 and g2 will each contain the same number of characters.
-dom, g1 and g2 will each contain between 1 and 50 characters, inclusive.
-Corresponding letters in g1 and g2 will have the same value, though potentially different cases.
 

Examples

0)
    
"AAAA"
"AAaa"
"DRDR"
Returns: "AAAa"
Whenever there are two 'A's, the return character is an 'A', and when there is one 'A' and one 'a', the return character is an 'A' only if the corresponding character in dom is a 'D'.
1)
    
"ABCDEFG"
"abcdefg"
"DDRRRDR"
Returns: "ABcdeFg"
2)
    
"Z"
"z"
"D"
Returns: "Z"
3)
    
"MGskgzTFQoclnDjZu"
"mgSKGzTFQoClnDJzU"
"DDDDDRDDDDRDDDDDD"
Returns: "MGSKGzTFQoclnDJZU"

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=5876&pm=2973

Writer:

lars2520

Testers:

PabloGilberto , vorthys

Problem categories:

String Manipulation