Advertisement
Spocoman

04. Snowwhite (90/100)

Apr 12th, 2023
740
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace Snowwhite
  6. {
  7.     class Program
  8.     {
  9.         public static void Main()
  10.         {
  11.             var dwarfs = new Dictionary<string, int>();
  12.  
  13.             string command;
  14.  
  15.             while ((command = Console.ReadLine()) != "Once upon a time")
  16.             {
  17.                 var dwarf = command.Split(" <:> ");
  18.                 string nameAndColor = dwarf[0] + '|' + dwarf[1];
  19.                 int physics = int.Parse(dwarf[2]);
  20.  
  21.                 if (!dwarfs.ContainsKey(nameAndColor))
  22.                 {
  23.                     dwarfs.Add(nameAndColor, physics);
  24.                 }
  25.  
  26.                 dwarfs[nameAndColor] = Math.Max(dwarfs[nameAndColor], physics);
  27.             }
  28.  
  29.             foreach (var dwarf in dwarfs
  30.                 .OrderByDescending(x => x.Value)
  31.                 .ThenByDescending(x => dwarfs.Where(c => c.Key.Split('|')[1] == x.Key.Split('|')[1])
  32.                 .Count()))
  33.             {
  34.                 Console.WriteLine($"({dwarf.Key.Split('|')[1]}) {dwarf.Key.Split('|')[0]} <-> {dwarf.Value}");
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement