Consider a tennis tournament with participants with names , where is a power of two. In the first round plays against , plays against , …, and plays against . The players that lose are eliminated, and the process is repeated with the remaining players. When only a player remains, this is the winner of the tournament.
For instance, let , and suppose that in the first round defeats , loses against , defeats , and defeats . In the second round plays against (suppose that wins), and plays against (suppose that wins). In the third and last round plays against . Assuming that wins, this is the champion. The following figure shows the championship just described:
Write a procedure that, given the names of the players and the table of results, returns the name of the winner of the tournament:
string winner(const vector<string>& name, const vector<bool>& win);
The vector @name@ has size , where is any power of 2. For each @j@ between 0 and , we have @name[j]@ . All the names are different.
For instance, this could be the table of names of the tournament previously described:
The vector @win@ has size and contains all the results of the matches: the first round is stored in the last positions, the second round is stored in the previous positions, the third round is stored in the previous positions, …, and the result of the last round (the final) is stored in @win[0]@. The boolean of each position indicates if the first player (the one with the smallest index) has won against the second one.
This would be the table of results of the tournament previously described:
For the example tournament, the answer should be
“Borg”.
You only need to submit the required procedure; your main program will be ignored.