Miki1337

Untitled

Mar 25th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Threading.Tasks;
  8. using System.Numerics;
  9.  
  10. namespace ConsoleApp1
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. string input;
  17. Dictionary<string, List<Dwarf>> alldwarfs = new Dictionary<string, List<Dwarf>>();
  18. List<Dwarf> result = new List<Dwarf>();
  19. while ((input = Console.ReadLine()) != "Once upon a time")
  20. {
  21. List<string> splitInput = input.Split(new[] { ' ', '<', '>', ':' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  22. string name = splitInput[0];
  23. string colour = splitInput[1];
  24. int physics = int.Parse(splitInput[2]);
  25.  
  26. if (!alldwarfs.ContainsKey(colour))
  27. {
  28. alldwarfs[colour] = new List<Dwarf>();
  29. }
  30. if (!alldwarfs[colour].Any(x => x.Name == name))
  31. {
  32. Dwarf dwarf = new Dwarf();
  33. dwarf.Name = name;
  34. dwarf.Physics = physics;
  35. dwarf.Colour = colour;
  36. alldwarfs[colour].Add(dwarf);
  37. result.Add(dwarf);
  38. }
  39. else
  40. {
  41. var tempDwarf = alldwarfs[colour].FirstOrDefault(x => x.Name == name);
  42. tempDwarf.Physics = Math.Max(tempDwarf.Physics, physics);
  43. }
  44. }
  45. result = result.OrderByDescending(x => x.Physics).ThenByDescending(a => alldwarfs[a.Colour].Count).ToList();
  46. foreach (var dwarf in result)
  47. {
  48.  
  49. Console.WriteLine($"({dwarf.Colour}) {dwarf.Name} <-> {dwarf.Physics}");
  50.  
  51. }
  52. }
  53. }
  54. class Dwarf
  55. {
  56. public string Name { get; set; }
  57. public string Colour { get; set; }
  58. public int Physics { get; set; }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment