TopCoder problem "Matching" used in SRM 176 (Division I Level One , Division II Level Two)



Problem Statement

    You are playing a game in which you have to find sets of three cards that share certain characteristics. Each card has some symbols on it. Each symbol is either a circle, a squiggle, or a diamond. Each symbol is either colored blue, red, or green. Each symbol is either solid, striped, or empty. And finally each card has either one, two, or three occurrences of the same symbol. A set is formed by three cards, and each characteristic is either the same on all three cards or different on all three cards.



For example, a card with one solid blue diamond, a card with two solid green diamonds, and a card with three solid red diamonds all form a set. The symbols on each card have the same shape and the same shading, and none of the cards has the same number or the same color. Any two cards will form a set with exactly one other card. You want to know, given two cards, what is the other card that completes the set. Create a class Matching with a method findMatch that takes two String[]s, first and second, representing the characteristics of two cards, and returns a String[] representing the characteristics of the third card.



first and second will both contain exactly four elements. The first element of each will denote the shape of the symbols on the card and will be either "CIRCLE", "SQUIGGLE", or "DIAMOND". The second element will denote the color and will be either "RED", "BLUE", or "GREEN". The third element of each will denote the shading and will be either "SOLID", "STRIPED", or "EMPTY". The fourth element of each will denote the number of symbols, and will be either "ONE", "TWO", or "THREE". The return element should contain exactly four elements, and should follow the same format as the input.
 

Definition

    
Class:Matching
Method:findMatch
Parameters:String[], String[]
Returns:String[]
Method signature:String[] findMatch(String[] first, String[] second)
(be sure your method is public)
    
 

Constraints

-first and second will both contain exactly four elements.
-The first element of first and second will be either "CIRCLE", "SQUIGGLE", or "DIAMOND".
-The second element of first and second will be either "RED", "BLUE", or "GREEN".
-The third element of first and second will be either "SOLID", "STRIPED", or "EMPTY".
-The fourth element of first and second will be either "ONE", "TWO", or "THREE".
 

Examples

0)
    
{"DIAMOND","BLUE","SOLID","ONE"}
{"DIAMOND","GREEN","SOLID","TWO"}
Returns: { "DIAMOND",  "RED",  "SOLID",  "THREE" }
The example from above.
1)
    
{"CIRCLE","GREEN","EMPTY","TWO"}
{"DIAMOND","BLUE","STRIPED","ONE"}
Returns: { "SQUIGGLE",  "RED",  "SOLID",  "THREE" }
All four characteristics are different on these two cards, so all four characteristics will be different on the third card in the set.
2)
    
{"DIAMOND","RED","SOLID","ONE"}
{"SQUIGGLE","BLUE","SOLID","TWO"}
Returns: { "CIRCLE",  "GREEN",  "SOLID",  "THREE" }
The only characteristic that is the same for all the cards in this set is that they are all solid.
3)
    
{"SQUIGGLE","RED","STRIPED","ONE"}
{"SQUIGGLE","RED","STRIPED","ONE"}
Returns: { "SQUIGGLE",  "RED",  "STRIPED",  "ONE" }

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4685&pm=2249

Writer:

Running Wild

Testers:

lbackstrom , brett1479

Problem categories:

Simple Search, Iteration