TheBulgarianWolf

Snowwhite

Mar 12th, 2021
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 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.         static void Main(string[] args)
  10.         {
  11.             string input;
  12.             Dictionary<string, int> dwarfs = new Dictionary<string, int>();
  13.             while((input = Console.ReadLine()) != "Once upon a time")
  14.             {
  15.                 string[] arr = input.Split(" <:> ");
  16.                 string name = arr[0];
  17.                 string color = arr[1];
  18.                 int power = int.Parse(arr[2]);
  19.                 string key = name + " " + color;
  20.                 if (dwarfs.ContainsKey(key) == false)
  21.                 {
  22.                     dwarfs.Add(key, power);
  23.                 }
  24.  
  25.                 if(dwarfs.ContainsKey(key) && dwarfs[key] < power)
  26.                 {
  27.                     dwarfs[key] = power;
  28.                 }
  29.             }
  30.  
  31.             foreach (var dwarf in dwarfs.OrderByDescending(k => k.Value)
  32.                 .ThenByDescending(c => dwarfs.Where(kvp => kvp.Key.Split(" ")[0] == c.Key.Split(" ")[0]).Count()))
  33.             {
  34.                 string value = dwarf.Key;
  35.                 string[] valueArr = value.Split();
  36.                 string color = "(" + valueArr[1] + ")";
  37.                 Console.WriteLine($"{color} {valueArr[0]} <-> {dwarf.Value}");
  38.             }
  39.         }
  40.     }
  41. }
  42.  
Add Comment
Please, Sign In to add comment