Advertisement
Taniaaleksandrova

04. Snowwhite

Jul 21st, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04._Snowwhite
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = string.Empty;
  12.  
  13.             var dwarfs = new Dictionary<string, Dictionary<string, int>>();
  14.  
  15.             while ((input = Console.ReadLine()) != "Once upon a time")
  16.             {
  17.                 string name = input.Split(" <:> ")[0];
  18.                 string color = input.Split(" <:> ")[1];
  19.                 int physics = int.Parse(input.Split(" <:> ")[2]);
  20.  
  21.                 if(dwarfs.ContainsKey(color))
  22.                 {
  23.                     if(dwarfs[color].ContainsKey(name))
  24.                     {
  25.                         if(dwarfs[color][name] < physics)
  26.                         {
  27.                             dwarfs[color][name] = physics;
  28.                         }
  29.                     }
  30.                     else
  31.                     {
  32.                         dwarfs[color].Add(name, physics);
  33.                     }
  34.                 }
  35.                 else
  36.                 {
  37.                     dwarfs.Add(color, new Dictionary<string, int>());
  38.                     dwarfs[color].Add(name, physics);
  39.                 }
  40.             }
  41.             dwarfs = dwarfs.OrderByDescending(x => x.Value.Values.Max()).ThenByDescending(x => x.Value.Values.Count).ToDictionary(a => a.Key, b => b.Value);
  42.             ;
  43.             foreach (var item in dwarfs)
  44.             {
  45.                 foreach (var items in dwarfs[item.Key].OrderByDescending(x => x.Value))
  46.                 {
  47.                     Console.WriteLine($"({item.Key}) {items.Key} <-> {items.Value}");
  48.                 }
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement