Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _4._Snowwhite
- {
- class Program
- {
- static void Main(string[] args)
- {
- var dict = new Dictionary<string, Dictionary<string, int>>();
- while (true)
- {
- string text = Console.ReadLine();
- if (text == "Once upon a time")
- {
- break;
- }
- else
- {
- string[] data = text
- .Split(" <:> ");
- string name = data[0];
- string colorHat = data[1];
- int physics = int.Parse(data[2]);
- if (!dict.ContainsKey(colorHat))
- {
- dict[colorHat] = new Dictionary<string, int>();
- dict[colorHat][name] = physics;
- }
- else
- {
- if (!dict[colorHat].ContainsKey(name))
- {
- dict[colorHat][name] = physics;
- }
- else
- {
- int currentPhysics = dict[colorHat][name];
- if (currentPhysics < physics)
- {
- dict[colorHat][name] = physics;
- }
- }
- }
- }
- }
- dict = dict
- .OrderByDescending(x => x.Value.Count())
- .ToDictionary(x => x.Key, z => z.Value);
- var sortedData = new Dictionary<string , int>();
- foreach (var kvp in dict)
- {
- foreach (var item in kvp.Value)
- {
- string currentName = $"({kvp.Key}) {item.Key} <->";
- sortedData[currentName] = item.Value;
- }
- }
- foreach (var kvp in sortedData
- .OrderByDescending(x=>x.Value))
- {
- Console.WriteLine($"{kvp.Key} {kvp.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment