SHARE
TWEET

Snowwhite

Nackey Jan 6th, 2018 (edited) 639 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Snowwhite
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var data = new Dictionary<string, Dictionary<string, int>>();
  14.  
  15.             string input = Console.ReadLine();
  16.  
  17.             while (input != "Once upon a time")
  18.             {
  19.                 var dwarfInfo = input.Split("<:> ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
  20.                 string color = dwarfInfo[1];
  21.                 string name = dwarfInfo[0];
  22.                 int physics = int.Parse(dwarfInfo[2]);
  23.  
  24.                 if (!data.ContainsKey(color))
  25.                 {
  26.                     data.Add(color, new Dictionary<string, int>());
  27.                     data[color][name] = physics;
  28.                 }
  29.                 else if (!data[color].ContainsKey(name))
  30.                 {
  31.                     data[color].Add(name, physics);
  32.                 }
  33.                 if (data[color][name] < physics)
  34.                 {
  35.                     data[color][name] = physics;
  36.                 }
  37.                 input = Console.ReadLine();
  38.             }
  39.             foreach (var color in data.OrderByDescending(x => x.Value.Values.Max()).ThenByDescending(x => x.Value.Count()))
  40.             {
  41.                 var dwarfs = color.Value;
  42.  
  43.                 foreach (var dwarf in dwarfs)
  44.                 {
  45.                     Console.Write($"({color.Key}) ");
  46.                     Console.WriteLine($"{dwarf.Key} <-> {dwarf.Value}");
  47.                 }
  48.             }
  49.         }
  50.     }
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top