Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Linq;
- using System.Collections.Generic;
- namespace SoftUniExamResults
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, Dictionary<string, int>> dwarves =
- new Dictionary<string, Dictionary<string, int>>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input=="Once upon a time")
- {
- break;
- }
- else
- {
- string[] split = input.Split(" <:> ");
- string name = split[0];
- string color = split[1];
- int size = int.Parse(split[2]);
- if (!dwarves.ContainsKey(name))
- {
- dwarves.Add(name, new Dictionary<string, int>());
- if (!dwarves[name].ContainsKey(color))
- {
- dwarves[name].Add(color, size);
- }
- }
- else
- {
- if (!dwarves[name].ContainsKey(color))
- {
- dwarves[name].Add(color, size);
- }
- else
- {
- if (size > dwarves[name][color])
- {
- dwarves[name][color] = size;
- }
- }
- }
- }
- }
- foreach (var dwarf in dwarves
- .OrderByDescending(x=>x.Value.Values.Sum()))
- //.ThenBy(x=>x.Value.Keys))
- {
- foreach (var item in dwarf.Value)
- {
- Console.WriteLine($"({item.Key}) {dwarf.Key} <-> {item.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment