Problem Statement
The number of teams in the tournament should be a power of 2 -- if it isn't, byes are added to the bracket. Byes are never placed so that they will "play" each other. When a team's opponent is "bye", there is no game played and the team automatically advances as if it had won a game. Here is an example with a bracket of length 4 containing one bye (see Example 0).
ROUND 1 ROUND 2 Duke |--------- Duke UCLA | |-------- MIT bye | |---------- MIT MIT
We have the tournament bracket (including any byes) from last year's tournament.
We also have a list of the results of the games in the order in which they
were played. We want to figure out who won last year's tournament. Create
a class Tourney that contains a method winner that is given
a
Definition
- Class:
- Tourney
- Method:
- winner
- Parameters:
- String[], String
- Returns:
- String
- Method signature:
- String winner(String[] bracket, String results)
- (be sure your method is public)
Notes
- it is possible that two teams with the same name could be in the tournament.
Constraints
- the number of elements in bracket will be a power of 2 between 2 and 32 inclusive
- each element in bracket will have length between 1 and 50 inclusive
- each element in bracket will contain only uppercase characters 'A'-'Z', or will be "bye"
- no two bye elements will be placed such that they would play each other
- the length of results will be exactly one less than the number of non-bye elements in bracket
- each character of results will be uppercase 'H' or uppercase 'L'
Examples
{"DUKE","UCLA","bye","MIT"}
"HL"
Returns: "MIT"
DUKE played UCLA in the first round and MIT advanced with a bye. DUKE won since the first game was won by the team higher on the bracket. In the second round, MIT beat DUKE since the second game was won by the lower team.
{"A","B","C","bye","D","E","F","bye"}
"LHHLH"
Returns: "B"
Round 1: B beat A, D beat E Round 2: B beat C, F beat D Round 3: B beat F
{"A","B","A","C","X","bye","bye","D", "E","F","G","H","I","J","K","L"}
"HLHLHLHLHLHLH"
Returns: "A"
{"A","B","A","C","X","bye","bye","D", "E","F","G","H","I","J","K","L"}
"HHHHHHHHHHHHH"
Returns: "A"
{"A","B","A","C","X","bye","bye","D", "E","F","G","H","I","J","K","L"}
"LHHLLHHLHLLLH"
Returns: "D"
{"MIT","bye"}
""
Returns: "MIT"
{"A","bye","A","bye","A","bye","A","bye","A","bye","A","bye","A","bye","A","bye", "A","bye","A","bye","A","bye","A","bye","A","bye","A","bye","A","bye","X","bye"}
"LLLLLLLLLLLLLLL";
Returns: "X"
{"P","Q","R","S","T","U","V","W","X","Y","Z","HARVARD","A","B","C","D", "P","Q","R","S","T","U","V","W","X","Y","Z","HARVARD","A","B","C","D"}
"LLLLLLLLLLLLLLLLLLLLLLLLHHHHLLL"
Returns: "HARVARD"
{"ABLE","BUTTER","CHALK","bye","bye","NORTHERN","X","bye"}
"HLHL"
Returns: "NORTHERN"
{"bye","ABCDEFGHIJKLM"}
""
Returns: "ABCDEFGHIJKLM"
{"WELL","bye","bye","MISS","AMERICAN","PIE","bye","CHEVY"}
"HHHH"
Returns: "WELL"
{"ONE","TWO","THREE","FOUR"}
"LHL"
Returns: "THREE"
{"A","B","A","C","X","bye","bye","D", "E","F","G","H","I","J","K","L"}
"LHHLLHHHHHLLH"
Returns: "X"
{"STANFORD","bye","STANFORD","bye"}
"L"
Returns: "STANFORD"
{"AUGUSTANA","DORDT"}
"H"
Returns: "AUGUSTANA"
{"AUGUSTANA","DORDT"}
"L"
Returns: "DORDT"
{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q", "R","S","T","U","V","W","X","Y","Z","AA","AB","AC","AD","AE","AF"}
"LHLHLHHLHLLHLLLHLHHLHHLHLHHHHHL"
Returns: "Q"
{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q", "R","S","T","U","V","W","X","Y","Z","AA","AB","AC","AD","AE","AF"}
"LHHHHLHLHLLHHLHLHHLHLLLLLLLLHLH"
Returns: "E"
{ "bye", "MIT" }
""
Returns: "MIT"
{ "A", "B", "C", "bye" }
"LH"
Returns: "B"
{ "DUKE", "BYE", "bye", "MIT" }
"HL"
Returns: "MIT"
{ "OIEJ", "PIERJPEIOWJ", "WOEIJFDS", "PWEJIOWE", "PWEOIJFEW", "OPFEJWPIOJE", "PEWFIOJPEFWJ", "PIEWURPWOWEPEOWIR", "PWEOIJUFDPSJ", "PWEORPEWOJ", "PEWOJPOEWJ", "OPWEIUJDPJV", "PWOIJEPOWEJ", "POIJEWTPWEJ", "PWEOITJPEWOIJTP", "WPOEITHJPEWTOJ" }
"LLLLLLLLLLLLLLL"
Returns: "WPOEITHJPEWTOJ"
{ "bye", "A" }
""
Returns: "A"
{ "bye", "X" }
""
Returns: "X"