Advertisement
social1986

Untitled

Jan 10th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Problem_4___Snowwhite
  8. {
  9.     public class Program
  10.     {
  11.         public static void Main()
  12.         {
  13.             var dwarfs = new Dictionary<string, Dictionary<string, int>>();
  14.  
  15.             while (true)
  16.             {
  17.                 var currentDwarf = Console.ReadLine()
  18.                     .Split(new string[] { " <:> " }, StringSplitOptions.RemoveEmptyEntries)
  19.                     .ToArray();
  20.  
  21.                 if (currentDwarf[0] == "Once upon a time")
  22.                 {
  23.                     break;
  24.                 }
  25.                 var name = currentDwarf[0];
  26.                 var hatColor = currentDwarf[1];
  27.                 var physics = int.Parse(currentDwarf[2]);
  28.  
  29.                 if (!dwarfs.ContainsKey(hatColor))
  30.                 {
  31.                     dwarfs[hatColor] = new Dictionary<string, int>();
  32.                 }
  33.                 if (!dwarfs[hatColor].ContainsKey(name))
  34.                 {
  35.                     dwarfs[hatColor][name] = physics;
  36.                 }
  37.                 else
  38.                 {
  39.                     if (dwarfs[hatColor][name] < physics)
  40.                     {
  41.                         dwarfs[hatColor][name] = physics;
  42.                     }
  43.                 }
  44.             }
  45.  
  46.             foreach (var dwarf in dwarfs.OrderByDescending(d => d.Value.Values))
  47.             {
  48.                 foreach (var dw in dwarf.Value)
  49.                 {
  50.                     Console.WriteLine($"({dwarf.Key}) {dw.Key} <-> {dw.Value}");
  51.                 }
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement