2
Reply

A tournament features 128 teams, and each match is a knockout match.

Jignesh Kumar

Jignesh Kumar

Jan 16
659
0
Reply

Write a program to determine the winner of a tournament and calculate the total number of matches required to identify the winner?

    using System; using System.Collections.Generic;class Tournament {static void Main(){int totalTeams = 128;List teams = new List();for (int i = 1; i <= totalTeams; i ){teams.Add("Team " i);}int round = 1;while (teams.Count > 1){Console.WriteLine($"Round {round}: {teams.Count} teams remaining");teams = KnockoutRound(teams);round ;}Console.WriteLine($"The winner is {teams[0]}!");}static List KnockoutRound(List teams){List winners = new List();for (int i = 0; i < teams.Count; i = 2){string winner = SimulateMatch(teams[i], teams[i 1]);winners.Add(winner);Console.WriteLine($"{teams[i]} vs {teams[i 1]} - Winner: {winner}");}return winners;}static string SimulateMatch(string team1, string team2){Random rand = new Random();return rand.Next(0, 2) == 0 ? team1 : team2;} }

    using System;

    class Tournament
    {
    public static void Main()
    {
    int totalTeams = 128; // Initial number of teams
    int totalMatches = totalTeams - 1; // Number of matches = teams - 1

    1. Console.WriteLine("Total matches played in the tournament: " + totalMatches);
    2. // Simulate the rounds
    3. int round = 1;
    4. int teamsInCurrentRound = totalTeams;
    5. while (teamsInCurrentRound > 1)
    6. {
    7. int matchesInCurrentRound = teamsInCurrentRound / 2;
    8. Console.WriteLine($"Round {round}: {matchesInCurrentRound} matches");
    9. // Half of the teams are eliminated in each round
    10. teamsInCurrentRound /= 2;
    11. round++;
    12. }
    13. }

    }

    Example Output:
    Total matches played in the tournament: 127
    Round 1: 64 matches
    Round 2: 32 matches
    Round 3: 16 matches
    Round 4: 8 matches
    Round 5: 4 matches
    Round 6: 2 matches
    Round 7: 1 matches