Advertisement
miroLLL

SnowWhite-Exam

Feb 25th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04Problem_SnowWhite
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string inputInfo = Console.ReadLine();
  12.  
  13.             var dwarfCollector = new Dictionary<string, Dictionary<string, uint>>();
  14.  
  15.             while (inputInfo != "Once upon a time")
  16.             {
  17.                 string[] dwarfInformator = inputInfo.Split(new char[] { ' ', '<', ':', '>' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  18.  
  19.                 string dwarfName = dwarfInformator[0];
  20.                 string dwarfHatColor = dwarfInformator[1];
  21.                 uint dwarfPhysics = uint.Parse(dwarfInformator[2]);
  22.  
  23.                 if (dwarfCollector.ContainsKey(dwarfName) == false)
  24.                 {
  25.                     dwarfCollector.Add(dwarfName, new Dictionary<string, uint>());
  26.                     dwarfCollector[dwarfName].Add(dwarfHatColor, dwarfPhysics);
  27.                 }
  28.                 else
  29.                 {
  30.                     if (dwarfCollector[dwarfName].ContainsKey(dwarfHatColor) == false)
  31.                     {
  32.                         dwarfCollector[dwarfName].Add(dwarfHatColor, dwarfPhysics);
  33.                     }
  34.                     else
  35.                     {
  36.                         uint currentPhysics = dwarfCollector[dwarfName][dwarfHatColor];
  37.  
  38.                         if (dwarfPhysics > currentPhysics)
  39.                         {
  40.                             dwarfCollector[dwarfName][dwarfHatColor] = dwarfPhysics;
  41.                         }
  42.                     }
  43.                 }
  44.  
  45.                 inputInfo = Console.ReadLine();
  46.             }
  47.  
  48.             foreach (var dwarf in dwarfCollector)
  49.             {
  50.                 foreach (var dwarfInfo in dwarf.Value.OrderByDescending(p => p.Value))
  51.                 {
  52.                     Console.WriteLine($"({dwarfInfo.Key}) {dwarf.Key} <-> {dwarfInfo.Value}");
  53.                 }
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement