mausha

WormsWorldParty

May 2nd, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. namespace WormsWorldParty
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     public class Party
  8.     {
  9.         public static void Main()
  10.         {
  11.             var input = Console.ReadLine().Split(new[] { "->" }, StringSplitOptions.RemoveEmptyEntries);
  12.  
  13.             var teams = new Dictionary<string, Team>();
  14.             var worms = new Dictionary<string, Dictionary<string, int>>();
  15.             while (input[0] != "quit")
  16.             {
  17.                 var wormName = input[0];
  18.                 var teamName = input[1];
  19.                 var wormScore = int.Parse(input[2]);
  20.                 if (!worms.Values.Any(w => w.ContainsKey(wormName)))
  21.                 {
  22.                     if (!teams.ContainsKey(teamName))
  23.                     {
  24.                         teams[teamName] = new Team();
  25.                         worms[teamName] = new Dictionary<string, int>();
  26.                     }
  27.  
  28.                     teams[teamName].TotalScore += wormScore;
  29.                     worms[teamName].Add(wormName, wormScore);
  30.                 }
  31.  
  32.                 input = Console.ReadLine().Split(new[] { "->" }, StringSplitOptions.RemoveEmptyEntries);
  33.             }
  34.  
  35.             foreach (var team in teams)
  36.             {
  37.                 team.Value.AverageScore = team.Value.TotalScore / worms[team.Key].Count();
  38.             }
  39.  
  40.             var counter = 1;
  41.             foreach (var team in teams.OrderByDescending(t => t.Value.TotalScore).ThenByDescending(t => t.Value.AverageScore))
  42.             {
  43.                 Console.WriteLine($"{counter}. Team:{team.Key}- {team.Value.TotalScore}");
  44.                
  45.                 foreach (var worm in worms[team.Key].OrderByDescending(w => w.Value))
  46.                 {
  47.                     Console.WriteLine($"###{worm.Key}: {worm.Value}");
  48.                 }
  49.  
  50.                 counter++;
  51.             }
  52.         }
  53.     }
  54. }
  55.  
  56. namespace WormsWorldParty
  57. {
  58.     public class Team
  59.     {
  60.         public long TotalScore { get; set; }
  61.  
  62.         public double AverageScore { get; set; }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment