Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main(string[] args)
- {
- int numSwimmers = 16;
- int numLanes = 4;
- int[,] results = new int[numSwimmers, numSwimmers];
- int[] strengths = new int[numSwimmers];
- GenerateResults(numSwimmers, numLanes, results);
- InitializeStrengths(numSwimmers, results, strengths);
- // Best 5 swimmers
- int[] topSwimmers = GetTopSwimmers(numSwimmers, strengths);
- // 1 to 5 place
- for (int i = 0; i < 5; i++)
- {
- Console.WriteLine($"Place {i + 1}: Swimmer {topSwimmers[i]}");
- }
- }
- static void GenerateResults(int numSwimmers, int numLanes, int[,] results)
- {
- // Generate random result
- Random random = new Random();
- for (int i = 0; i < numSwimmers; i++)
- {
- for (int j = i + 1; j < numSwimmers; j++)
- {
- int winner = random.Next(2); // 0 - i winner, 1 - j winner
- results[i, j] = winner;
- results[j, i] = 1 - winner;
- }
- }
- }
- static void InitializeStrengths(int numSwimmers, int[,] results, int[] strengths)
- {
- for (int i = 0; i < numSwimmers; i++)
- {
- strengths[i] = 0;
- }
- for (int i = 0; i < numSwimmers; i++)
- {
- for (int j = 0; j < numSwimmers; j++)
- {
- if (i != j && results[i, j] == 1)
- {
- strengths[i]++;
- }
- }
- }
- }
- static int[] GetTopSwimmers(int numSwimmers, int[] strengths)
- {
- // Best 5 swimmers
- int[] topSwimmers = new int[5];
- for (int i = 0; i < 5; i++)
- {
- int maxStrength = -1;
- int maxIndex = -1;
- for (int j = 0; j < numSwimmers; j++)
- {
- if (strengths[j] > maxStrength)
- {
- maxStrength = strengths[j];
- maxIndex = j;
- }
- }
- topSwimmers[i] = maxIndex;
- strengths[maxIndex] = -1;
- }
- return topSwimmers;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement