Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _04Problem_SnowWhite
- {
- class Program
- {
- static void Main(string[] args)
- {
- string inputInfo = Console.ReadLine();
- var dwarfCollector = new Dictionary<string, Dictionary<string, uint>>();
- while (inputInfo != "Once upon a time")
- {
- string[] dwarfInformator = inputInfo.Split(new char[] { ' ', '<', ':', '>' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- string dwarfName = dwarfInformator[0];
- string dwarfHatColor = dwarfInformator[1];
- uint dwarfPhysics = uint.Parse(dwarfInformator[2]);
- if (dwarfCollector.ContainsKey(dwarfName) == false)
- {
- dwarfCollector.Add(dwarfName, new Dictionary<string, uint>());
- dwarfCollector[dwarfName].Add(dwarfHatColor, dwarfPhysics);
- }
- else
- {
- if (dwarfCollector[dwarfName].ContainsKey(dwarfHatColor) == false)
- {
- dwarfCollector[dwarfName].Add(dwarfHatColor, dwarfPhysics);
- }
- else
- {
- uint currentPhysics = dwarfCollector[dwarfName][dwarfHatColor];
- if (dwarfPhysics > currentPhysics)
- {
- dwarfCollector[dwarfName][dwarfHatColor] = dwarfPhysics;
- }
- }
- }
- inputInfo = Console.ReadLine();
- }
- foreach (var dwarf in dwarfCollector)
- {
- foreach (var dwarfInfo in dwarf.Value.OrderByDescending(p => p.Value))
- {
- Console.WriteLine($"({dwarfInfo.Key}) {dwarf.Key} <-> {dwarfInfo.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement