silvana1303

basketball tournament

Apr 27th, 2020
646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1. using System;
  2.  
  3. namespace exampreparation
  4.  
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string tournamentName = Console.ReadLine();
  11.            
  12.             int matchCount = 0;
  13.             int desiWins = 0;
  14.             int desiLoss = 0;
  15.             int diffPoints = 0;
  16.            
  17.  
  18.             while (tournamentName != "End of tournaments")
  19.             {
  20.                 int gamesCount = int.Parse(Console.ReadLine());
  21.                 matchCount += gamesCount;
  22.  
  23.                 for (int i = 1; i <= gamesCount; i++)
  24.                 {
  25.                    
  26.                     int desiTeam = int.Parse(Console.ReadLine());
  27.                     int otherTeam = int.Parse(Console.ReadLine());
  28.  
  29.                     if (desiTeam > otherTeam)
  30.                     {
  31.                         desiWins++;
  32.                         diffPoints = desiTeam - otherTeam;
  33.                         Console.WriteLine($"Game {i} of tournament {tournamentName}: win with {diffPoints} points.");
  34.                     }
  35.                     else
  36.                     {
  37.                         desiLoss++;
  38.                         diffPoints = otherTeam - desiTeam;
  39.                         Console.WriteLine($"Game {i} of tournament {tournamentName}: lost with {diffPoints} points.");
  40.                     }
  41.                 }
  42.  
  43.                 tournamentName = Console.ReadLine();
  44.                
  45.             }
  46.  
  47.             double percentWins = desiWins * 1.0 / matchCount * 100.0;
  48.             double percentLoses = desiLoss * 1.0 / matchCount * 100.0;
  49.  
  50.             if (tournamentName == "End of tournaments")
  51.             {
  52.                 Console.WriteLine($"{percentWins:f2}% matches win");
  53.                 Console.WriteLine($"{percentLoses:F2}% matches lost");
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment