Advertisement
YavorGrancharov

SoftUni_Beer_Pong(lambda)

Jul 18th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace SoftUni_Beer_Pong
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<string, Dictionary<string, int>> equip =
  12.                 new Dictionary<string, Dictionary<string, int>>();
  13.  
  14.             string[] input = Console.ReadLine().Split('|');
  15.  
  16.             while (input[0] != "stop the game")
  17.             {
  18.                 string player = input[0];
  19.                 string team = input[1];
  20.                 string points = input[2];
  21.  
  22.                 if (!equip.ContainsKey(team))
  23.                 {
  24.                     equip.Add(team, new Dictionary<string, int>());
  25.                 }
  26.                 if (equip[team].Count < 3)
  27.                 {
  28.                     equip[team][player] = int.Parse(points);
  29.                 }
  30.                
  31.                 input = Console.ReadLine().Split('|');
  32.             }
  33.  
  34.             equip = equip
  35.                 .Where(p => p.Value.Keys.Count == 3)
  36.                 .ToDictionary(k => k.Key, p => p.Value)
  37.                 .OrderByDescending(p => p.Value.Values.Sum())
  38.                 .ToDictionary(k => k.Key, p => p.Value);
  39.  
  40.             int index = 1;
  41.             foreach (KeyValuePair<string, Dictionary<string, int>> team in equip)
  42.             {
  43.                 Console.WriteLine("{0}. {1}; Players:", index, team.Key);
  44.  
  45.                 Dictionary<string, int> teamsPoints = team.Value
  46.                     .OrderByDescending(p => p.Value)
  47.                     .ToDictionary(k => k.Key, p => p.Value);
  48.  
  49.                 foreach (KeyValuePair<string, int> printTeams in teamsPoints
  50.                     .OrderByDescending(p => p.Value))
  51.                 {                  
  52.                     Console.WriteLine("###{0}: {1}", printTeams.Key, printTeams.Value);
  53.                 }
  54.                 index++;
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement