Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Problem_4___Snowwhite
- {
- public class Program
- {
- public static void Main()
- {
- var dwarfs = new Dictionary<string, Dictionary<string, int>>();
- while (true)
- {
- var currentDwarf = Console.ReadLine()
- .Split(new string[] { " <:> " }, StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- if (currentDwarf[0] == "Once upon a time")
- {
- break;
- }
- var name = currentDwarf[0];
- var hatColor = currentDwarf[1];
- var physics = int.Parse(currentDwarf[2]);
- if (!dwarfs.ContainsKey(hatColor))
- {
- dwarfs[hatColor] = new Dictionary<string, int>();
- }
- if (!dwarfs[hatColor].ContainsKey(name))
- {
- dwarfs[hatColor][name] = physics;
- }
- else
- {
- if (dwarfs[hatColor][name] < physics)
- {
- dwarfs[hatColor][name] = physics;
- }
- }
- }
- foreach (var dwarf in dwarfs.OrderByDescending(d => d.Value.Values))
- {
- foreach (var dw in dwarf.Value)
- {
- Console.WriteLine($"({dwarf.Key}) {dw.Key} <-> {dw.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement