nikolapetkov824

P04.Snowwhite

Dec 7th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5.  
  6. namespace SoftUniExamResults
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Dictionary<string, Dictionary<string, int>> dwarves =
  13.                 new Dictionary<string, Dictionary<string, int>>();
  14.  
  15.             while (true)
  16.             {
  17.                 string input = Console.ReadLine();
  18.  
  19.                 if (input=="Once upon a time")
  20.                 {
  21.                     break;
  22.                 }
  23.                 else
  24.                 {
  25.                     string[] split = input.Split(" <:> ");
  26.  
  27.                     string name = split[0];
  28.                     string color = split[1];
  29.                     int size = int.Parse(split[2]);
  30.  
  31.                     if (!dwarves.ContainsKey(name))
  32.                     {
  33.                         dwarves.Add(name, new Dictionary<string, int>());
  34.  
  35.                         if (!dwarves[name].ContainsKey(color))
  36.                         {
  37.                             dwarves[name].Add(color, size);
  38.                         }
  39.                     }
  40.                     else
  41.                     {
  42.                         if (!dwarves[name].ContainsKey(color))
  43.                         {
  44.                             dwarves[name].Add(color, size);
  45.                         }
  46.                         else
  47.                         {
  48.                             if (size > dwarves[name][color])
  49.                             {
  50.                                 dwarves[name][color] = size;
  51.                             }
  52.                         }
  53.                     }
  54.                 }
  55.             }
  56.  
  57.             foreach (var dwarf in dwarves
  58.                 .OrderByDescending(x=>x.Value.Values.Sum()))
  59.                 //.ThenBy(x=>x.Value.Keys))
  60.             {
  61.                 foreach (var item in dwarf.Value)
  62.                 {
  63.                     Console.WriteLine($"({item.Key}) {dwarf.Key} <-> {item.Value}");
  64.                 }
  65.             }
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment