Advertisement
Guest User

Untitled

a guest
Jan 7th, 2018
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Snowmen
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<Dwarf> dwarfs = new List<Dwarf>();
  12. string input = Console.ReadLine();
  13. while (input != "Once upon a time")
  14. {
  15. string[] inputs = input.Split(new string[] { " <:> " }, StringSplitOptions.None);
  16. string name = inputs[0];
  17. string color = inputs[1];
  18. int physics = int.Parse(inputs[2]);
  19.  
  20. Dwarf repeat = dwarfs.Find(x => x.Name == name && x.Color == color);
  21. if (repeat == null)
  22. {
  23. Dwarf dwarf = new Dwarf(name, color, physics);
  24. dwarfs.Add(dwarf);
  25. }
  26. else
  27. {
  28. repeat.Physics = Math.Max(repeat.Physics, physics);
  29. }
  30. input = Console.ReadLine();
  31. }
  32. foreach (var dwarf in dwarfs
  33. .OrderByDescending(x => x.Physics)
  34. .ThenByDescending(x => dwarfs.Count(y => y.Color == x.Color)))
  35. {
  36. Console.WriteLine("({0}) {1} <-> {2}", dwarf.Color, dwarf.Name, dwarf.Physics);
  37. }
  38. }
  39. }
  40.  
  41. class Dwarf
  42. {
  43. public string Name { get; set; }
  44. public string Color { get; set; }
  45. public int Physics { get; set; }
  46.  
  47. public Dwarf(string name, string color, int physics)
  48. {
  49. Name = name;
  50. Color = color;
  51. Physics = physics;
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement