Advertisement
cortez

FootballStatistician

Oct 11th, 2015
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Problem_02__Football_Statistician
  5. {
  6.     class FootballStatistician
  7.     {
  8.         public static void Main ()
  9.         {
  10.             double eurosPaid = double.Parse (Console.ReadLine());
  11.             int numberOfGames = 0;
  12.             const string endMessage = "End of the league.";
  13.  
  14.             // Teams...
  15.             Dictionary<string, Team> teams = new Dictionary<string, Team> ()
  16.             {
  17.                 {"Arsenal", new Team("Arsenal", 0)},
  18.                 {"Chelsea", new Team("Chelsea", 0)},
  19.                 {"Everton", new Team("Everton", 0)},
  20.                 {"Liverpool", new Team("Liverpool", 0)},
  21.                 {"ManchesterCity", new Team("Manchester City", 0)},
  22.                 {"ManchesterUnited", new Team("Manchester United", 0)},
  23.                 {"Southampton", new Team("Southampton", 0)},
  24.                 {"Tottenham", new Team("Tottenham", 0)}
  25.             };
  26.  
  27.             string gamesInput = Console.ReadLine ();
  28.             while (!String.Equals(gamesInput, endMessage))
  29.             {
  30.                 List<string> gameInfo = CleanInput(gamesInput.Split (' '));
  31.                 CalculateScore (teams, gameInfo[0], gameInfo[1], gameInfo[2]);
  32.  
  33.                 numberOfGames++;
  34.  
  35.                 gamesInput = Console.ReadLine ();
  36.             }
  37.  
  38.             Console.WriteLine ("{0:0.00}lv.", (eurosPaid * numberOfGames) * 1.94);
  39.             foreach(KeyValuePair<string, Team> team in teams)
  40.             {
  41.                 Console.WriteLine (team.Value.PrintPoints());
  42.             }
  43.         }
  44.  
  45.         public static List<string> CleanInput (string[] input)
  46.         {
  47.             List<string> cleaned = new List<string> ();
  48.  
  49.             foreach (string item in input)
  50.             {
  51.                 if (!String.IsNullOrEmpty(item))
  52.                 {
  53.                     cleaned.Add (item);
  54.                 }
  55.             }
  56.  
  57.             return cleaned;
  58.         }
  59.  
  60.         public static void CalculateScore (Dictionary<string, Team> teams, string team1, string result, string team2)
  61.         {
  62.             switch (result)
  63.             {
  64.             case "1":
  65.                 teams [team1].points += 3;
  66.                 break;
  67.             case "X":
  68.                 teams [team1].points += 1;
  69.                 teams [team2].points += 1;
  70.                 break;
  71.             case "2":
  72.                 teams [team2].points += 3;
  73.                 break;
  74.             }
  75.         }
  76.     }
  77.     class Team
  78.     {
  79.         public string name { get; set; }
  80.         public sbyte points { get; set; }
  81.  
  82.         public Team(string name, sbyte points)
  83.         {
  84.             this.name = name;
  85.             this.points = points;
  86.         }
  87.  
  88.         public string PrintPoints ()
  89.         {
  90.             return name + " - " + points + " points.";
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement