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 Snow_White
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int> dwarves = new Dictionary<string, int>();
- string input = Console.ReadLine();
- Dictionary<string, int> hatColors = new Dictionary<string, int>();
- while (input != "Once upon a time")
- {
- string[] inputParams = input
- .Split(new string[] { " <:> " },
- StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- string dwarfName = inputParams[0];
- string hatColor = inputParams[1];
- int physics = int.Parse(inputParams[2]);
- string concatenated = "("+ hatColor + ") " + dwarfName;
- string colors = "(" + hatColor + ")";
- if (!dwarves.ContainsKey(concatenated))
- {
- dwarves.Add(concatenated, physics);
- if (!hatColors.ContainsKey(colors))
- {
- hatColors.Add(colors, 1);
- }
- else
- {
- hatColors[colors]++;
- }
- }
- else
- {
- if (physics > dwarves[concatenated])
- {
- dwarves[concatenated] = physics;
- }
- }
- input = Console.ReadLine();
- }
- foreach (var kvp in dwarves.OrderByDescending(x => x.Value).ThenByDescending(x=>hatColors[x.Key.Split(new [] { ' ' },
- StringSplitOptions.RemoveEmptyEntries).First()]))
- {
- Console.WriteLine("{0} <-> {1}", kvp.Key, kvp.Value);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement