Advertisement
ivo_petkov01

06. Basketball Tournament

Jan 11th, 2023
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _06._Basketball_Tournament
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int dessiWins = 0;
  10.             int dessiLosts = 0;
  11.             int totalMathes = 0;
  12.  
  13.             while (true)
  14.             {
  15.                 string command = Console.ReadLine();
  16.  
  17.                 if (command == "End of tournaments")
  18.                 {
  19.                     break;
  20.                 }
  21.  
  22.                 string tourName = command;
  23.                 int matchesCount = int.Parse(Console.ReadLine());
  24.  
  25.                 for (int i = 1; i <= matchesCount; i++)
  26.                 {
  27.                     int dessiScore = int.Parse(Console.ReadLine());
  28.                     int opponentScore = int.Parse(Console.ReadLine());
  29.  
  30.                     if (dessiScore > opponentScore)
  31.                     {
  32.                         dessiWins++;
  33.                         int diff = dessiScore - opponentScore;
  34.                         Console.WriteLine($"Game {i} of tournament {tourName}: win with {diff} points.");
  35.                     }
  36.                     else if (dessiScore < opponentScore)
  37.                     {
  38.                         dessiLosts++;
  39.                         int diff = opponentScore - dessiScore;
  40.                         Console.WriteLine($"Game {i} of tournament {tourName}: lost with {diff} points.");
  41.                     }
  42.                 }
  43.  
  44.                 totalMathes += matchesCount;
  45.             }
  46.  
  47.             double winsPercent = dessiWins / (totalMathes * 1.0) * 100;
  48.             double lostsPercent = dessiLosts / (totalMathes * 1.0) * 100;
  49.  
  50.             Console.WriteLine($"{winsPercent:f2}% matches win");
  51.             Console.WriteLine($"{lostsPercent:f2}% matches lost");
  52.         }
  53.     }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement