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;
- class SnW_2varRABOTI
- {
- static void Main()
- {
- var input = Console.ReadLine();
- var dwarfs = new Dictionary<KeyValuePair<string, string>, long>();
- var colors = new Dictionary<string, int>();
- while (input != "Once upon a time")
- {
- var dwarfInput = input.Split(new string[] { " <:> " }, StringSplitOptions.RemoveEmptyEntries);
- var dwarfName = dwarfInput[0];
- var dwarfHatColor = dwarfInput[1];
- var dwarfPhysics = int.Parse(dwarfInput[2]);
- var dwarf = new KeyValuePair<string, string>(dwarfName, dwarfHatColor);
- if (!dwarfs.ContainsKey(dwarf))
- {
- dwarfs.Add(dwarf, dwarfPhysics);
- if (!colors.ContainsKey(dwarfHatColor))
- {
- colors.Add(dwarfHatColor, 0);
- }
- colors[dwarfHatColor]++;
- }
- else
- {
- if (dwarfPhysics > dwarfs[dwarf])
- {
- dwarfs[dwarf] = dwarfPhysics;
- }
- }
- input = Console.ReadLine();
- }
- //---------------------------------------------------
- var sorted = dwarfs
- .OrderByDescending(x => x.Value)
- .ThenByDescending(x => colors[x.Key.Value])
- .ToDictionary(x => x.Key, x => x.Value);
- foreach (var dwarf in sorted)
- {
- var hatColor = dwarf.Key.Value;
- var name = dwarf.Key.Key;
- var physics = dwarf.Value;
- Console.WriteLine("({0}) {1} <-> {2}", hatColor, name, physics);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement