Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Statement In a single-elimination tournament, the schedule is determined by placing the teams in a vertical list called the tournament bracket. In the first

Problem Statement

In a single-elimination tournament, the schedule is determined by placing the teams in a vertical list called "the tournament bracket". In the first round the top two teams in the bracket play each other, then the next two, etc. In the second round the top two remaining teams play each other, then the next two, etc. This continues until there is only one team left -- the tournament winner.

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 a previous 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 the tournament. Create a function winner that is given a Vector of strings bracket and a string resultsand that returns the name of the winning team as a string. The bracket is given in order from top to bottom, and the results are given as a string of 'H' or 'L' indicating for each game (in the order in which the games were played) whether the Higher or Lower team from the bracket won that game. The string results contains a character for each real game, but not for byes.

Notes and Constraints

-It is possible that two teams with the same name could be in the tournament.

-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

bracket = {"DUKE","UCLA","bye","MIT"} results = "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.

Starter code (Cannot be changed and all code must be within the bolded code):

string winner(Vector bracket, string results) { // fill in code here }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions

Question

What are the three possible levels of concurrency in programs?

Answered: 1 week ago