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 DictMoreExc4
- {
- class Program
- {
- static void Main(string[] args)
- {
- var dwarfs = new Dictionary<string, Dictionary<string, int>>();
- var sortedDwarfs = new Dictionary<string, int>();
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "Once upon a time")
- {
- foreach (var hatcolor in dwarfs.OrderByDescending(x => x.Value.Count()))
- {
- foreach (var dwarf in hatcolor.Value)
- {
- sortedDwarfs.Add($"({hatcolor.Key}) {dwarf.Key} <-> ", dwarf.Value);
- }
- }
- foreach (var item in sortedDwarfs.OrderByDescending(x => x.Value))
- {
- Console.WriteLine(item.Key + item.Value);
- }
- break;
- }
- var split = command.Split(new string[] { " <:> " }, StringSplitOptions.None).ToList();
- string DwarfName = split[0];
- string DwarfColor = split[1];
- int DwarfPoints = int.Parse(split[2]);
- if (!dwarfs.ContainsKey(DwarfColor))
- {
- dwarfs.Add(DwarfColor, new Dictionary<string, int>());
- dwarfs[DwarfColor].Add(DwarfName, DwarfPoints);
- }
- else if (dwarfs.ContainsKey(DwarfColor))
- {
- if (!dwarfs[DwarfColor].ContainsKey(DwarfName))
- {
- dwarfs[DwarfColor].Add(DwarfName, DwarfPoints);
- }
- else
- {
- if (dwarfs[DwarfColor][DwarfName] < DwarfPoints)
- {
- dwarfs[DwarfColor][DwarfName] = DwarfPoints;
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement