Advertisement
Guest User

Snow White

a guest
Mar 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 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 Snow_White
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, int> dwarves = new Dictionary<string, int>();
  14.             string input = Console.ReadLine();
  15.             Dictionary<string, int> hatColors = new Dictionary<string, int>();
  16.  
  17.  
  18.             while (input != "Once upon a time")
  19.             {
  20.                 string[] inputParams = input
  21.                     .Split(new string[] { " <:> " },
  22.                     StringSplitOptions.RemoveEmptyEntries)
  23.                     .ToArray();
  24.  
  25.                 string dwarfName = inputParams[0];
  26.                 string hatColor = inputParams[1];
  27.                 int physics = int.Parse(inputParams[2]);
  28.  
  29.                 string concatenated = "("+ hatColor + ") " + dwarfName;
  30.  
  31.                 string colors = "(" + hatColor + ")";
  32.  
  33.                 if (!dwarves.ContainsKey(concatenated))
  34.                 {
  35.                     dwarves.Add(concatenated, physics);
  36.                     if (!hatColors.ContainsKey(colors))
  37.                     {
  38.                         hatColors.Add(colors, 1);
  39.                     }
  40.                     else
  41.                     {
  42.                         hatColors[colors]++;
  43.                     }
  44.                 }
  45.  
  46.                 else
  47.                 {
  48.                     if (physics > dwarves[concatenated])
  49.                     {
  50.                         dwarves[concatenated] = physics;
  51.                     }
  52.                 }
  53.  
  54.                 input = Console.ReadLine();
  55.             }
  56.             foreach (var kvp in dwarves.OrderByDescending(x => x.Value).ThenByDescending(x=>hatColors[x.Key.Split(new [] { ' ' },
  57.                    StringSplitOptions.RemoveEmptyEntries).First()]))
  58.             {
  59.                 Console.WriteLine("{0} <-> {1}", kvp.Key, kvp.Value);
  60.             }
  61.  
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement