Advertisement
Guest User

Untitled

a guest
Jun 29th, 2018
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5.  
  6. namespace _4._Snowwhite
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. Dictionary<string, int> dwarfs = new Dictionary<string, int>();
  13.  
  14. string[] input = Console.ReadLine()
  15. .Split(" <:> ")
  16. .ToArray();
  17.  
  18. while (input[0] != "Once upon a time")
  19. {
  20. string name = input[0];
  21. string color = input[1];
  22. int physics = int.Parse(input[2]);
  23.  
  24. string spec = name + "-" + color;
  25.  
  26. // if dwarf does not exist
  27. if (dwarfs.ContainsKey(spec)==false)
  28. {
  29. dwarfs.Add(spec, physics);
  30. }
  31. else
  32. //if 2 dwarfs have the same name and the same color,store the one with the higher physics.
  33. {
  34. if (dwarfs[spec] < physics)
  35. {
  36. dwarfs[spec] = physics;
  37. }
  38.  
  39. }
  40.  
  41. input = Console.ReadLine()
  42. .Split(" <:> ")
  43. .ToArray();
  44. }
  45.  
  46. Console.WriteLine();
  47.  
  48. foreach (var pair in dwarfs
  49. .OrderByDescending(x=>x.Value)
  50. .ThenByDescending(x=>dwarfs.Where(y => y.Key.Split("-")[1] == x.Key.Split("-")[1])
  51. .Count())
  52. )
  53. {
  54.  
  55. Console.WriteLine("({0}) {1} <-> {2}",
  56. pair.Key.Split('-')[1],
  57. pair.Key.Split('-')[0],
  58. pair.Value);
  59. }
  60.  
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement