Exemple #1
0
        static ChampionshipMetrics GetChampionshipMetrics(int[,] matrix, int numberOfRowsAndColumns)
        {
            ChampionshipMetrics championshipmetrics = new ChampionshipMetrics();

            championshipmetrics.ThereIsOneTeamWhichWonMoreThanHalfOfGames = false;
            for (int i = 0; i < numberOfRowsAndColumns; i++)
            {
                int countFails   = 0;
                int countVictory = 0;
                for (int j = 0; j < numberOfRowsAndColumns; j++)
                {
                    if (i != j)
                    {
                        if (matrix[j, i] == 0)
                        {
                            countFails++;
                        }
                        if (matrix[j, i] == 2)
                        {
                            countVictory++;
                        }
                    }
                }

                ProcessTeam(countVictory, countFails, championshipmetrics, i);

                if (countVictory > numberOfRowsAndColumns / 2)
                {
                    championshipmetrics.ThereIsOneTeamWhichWonMoreThanHalfOfGames = true;
                }
            }
            return(championshipmetrics);
        }
Exemple #2
0
        static void ProcessTeam(int countVictory, int countFails, ChampionshipMetrics championshipMetrics, int index)
        {
            if (countFails == 0)
            {
                championshipMetrics.TeamsWithoutFails = rewriteArray(championshipMetrics.TeamsWithoutFails, index);
            }

            if (countVictory > countFails)
            {
                championshipMetrics.NumberOfTeamsWhichWonMoreThanLost++;
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            int numberOfRowsAndColumns = ReadInt("number of rows and columns is ");

            int[,] matrix = new int[numberOfRowsAndColumns, numberOfRowsAndColumns];
            Random random = new Random();


            for (int i = 0; i < numberOfRowsAndColumns; i++)
            {
                for (int j = 0; j < numberOfRowsAndColumns; j++)
                {
                    if (i == j)
                    {
                        matrix[j, i] = 0;
                    }
                    else
                    {
                        matrix[j, i] = random.Next(0, 3);
                    }
                }
            }
            DisplayMatrix(matrix);

            ChampionshipMetrics championshipMetrics = GetChampionshipMetrics(matrix, numberOfRowsAndColumns);

            if (championshipMetrics.TeamsWithoutFails != null)
            {
                for (int i = 0; i < championshipMetrics.TeamsWithoutFails.Length; i++)
                {
                    Console.WriteLine($"team without fails is: {championshipMetrics.TeamsWithoutFails[i]}");
                }
            }
            Console.WriteLine($"number of commands which won more than failed {championshipMetrics.NumberOfTeamsWhichWonMoreThanLost}, " + "\n" +
                              $"is there at least one command which won more than half of games - {championshipMetrics.ThereIsOneTeamWhichWonMoreThanHalfOfGames}");
            Console.ReadKey();
        }