Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Problem04Exam05012018
- {
- internal class Program
- {
- private static void Main(string[] args)
- {
- var dwarfs = new List<Dwarf>();
- string input;
- while (!(input = Console.ReadLine()).Equals("Once upon a time"))
- {
- var tokens = input.Split(new[] { " <:> " }, StringSplitOptions.RemoveEmptyEntries);
- var name = tokens[0];
- var color = tokens[1];
- var physics = int.Parse(tokens[2]);
- if (!dwarfs.Any(p => p.Name == name && p.HatColor == color))
- {
- dwarfs.Add(new Dwarf() { Name = name, HatColor = color, Physics = physics });
- }
- else
- {
- if (dwarfs.First(p => p.Name == name && p.HatColor == color).Physics < physics)
- {
- dwarfs.First(p => p.Name == name && p.HatColor == color).Physics = physics;
- }
- }
- }
- var hatCollection = new Dictionary<string, List<string>>();
- foreach (var dwarf in dwarfs)
- {
- if (!hatCollection.ContainsKey(dwarf.HatColor))
- {
- hatCollection.Add(dwarf.HatColor, new List<string>());
- }
- hatCollection[dwarf.HatColor].Add(dwarf.Name);
- }
- foreach (var dwarf in dwarfs.OrderByDescending(p => p.Physics).ThenByDescending(p => hatCollection[p.HatColor].Count))
- {
- Console.WriteLine($"({dwarf.HatColor}) {dwarf.Name} <-> {dwarf.Physics}");
- }
- }
- }
- internal class Dwarf
- {
- public string Name { get; set; }
- public string HatColor { get; set; }
- public int Physics { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement