Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. var input = Console.ReadLine();
  2.  
  3.             var worms = new Dictionary<string, int>();
  4.             var teams = new Dictionary<string, List<Team>>();
  5.            
  6.  
  7.             while (input != "quit")
  8.             {
  9.                 var tokens = input.Split(new[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  10.                 var wormName = tokens[0];
  11.                 var wormTeam = tokens[1];
  12.                 var wormScore = int.Parse(tokens[2]);
  13.                
  14.                 if (!worms.ContainsKey(wormName))
  15.                 {
  16.                     worms.Add(wormName, wormScore);
  17.                 }
  18.                 var currentTeam = new Team
  19.                 {
  20.                     Name = wormTeam,
  21.                     Worms = worms,
  22.                     TotalScore = 0,
  23.                     AverageScore = 0
  24.                 };
  25.  
  26.                 if (!teams.ContainsKey(wormTeam))
  27.                 {
  28.                     teams[wormTeam] = new List<Team>();
  29.                 }
  30.                 teams[wormTeam].Add(currentTeam);
  31.  
  32.                 input = Console.ReadLine();
  33.             }
  34.  
  35.             foreach (var team in teams)
  36.             {
  37.                 var currentTeams = team.Value;
  38.                 foreach (var currentteam in currentTeams)
  39.                 {
  40.                     foreach (var item in currentteam.Worms)
  41.                     {
  42.                         currentteam.TotalScore += item.Value;
  43.                     }
  44.                     currentteam.AverageScore = currentteam.TotalScore / currentteam.Worms.Count;
  45.                 }
  46.                 currentTeams = currentTeams.OrderByDescending(x => x.TotalScore).ThenByDescending(x => x.AverageScore).ToList();
  47.                 var count = 1;
  48.                 Console.WriteLine($"{count}. Team : {team.Key}");
  49.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement