Advertisement
Dora_dnd

Untitled

Feb 25th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class SnW_2varRABOTI
  8. {
  9. static void Main()
  10. {
  11. var input = Console.ReadLine();
  12. var dwarfs = new Dictionary<KeyValuePair<string, string>, long>();
  13. var colors = new Dictionary<string, int>();
  14. while (input != "Once upon a time")
  15. {
  16. var dwarfInput = input.Split(new string[] { " <:> " }, StringSplitOptions.RemoveEmptyEntries);
  17. var dwarfName = dwarfInput[0];
  18. var dwarfHatColor = dwarfInput[1];
  19. var dwarfPhysics = int.Parse(dwarfInput[2]);
  20.  
  21. var dwarf = new KeyValuePair<string, string>(dwarfName, dwarfHatColor);
  22.  
  23. if (!dwarfs.ContainsKey(dwarf))
  24. {
  25. dwarfs.Add(dwarf, dwarfPhysics);
  26. if (!colors.ContainsKey(dwarfHatColor))
  27. {
  28. colors.Add(dwarfHatColor, 0);
  29. }
  30. colors[dwarfHatColor]++;
  31. }
  32. else
  33. {
  34. if (dwarfPhysics > dwarfs[dwarf])
  35. {
  36. dwarfs[dwarf] = dwarfPhysics;
  37. }
  38. }
  39.  
  40. input = Console.ReadLine();
  41. }
  42. //---------------------------------------------------
  43. var sorted = dwarfs
  44. .OrderByDescending(x => x.Value)
  45. .ThenByDescending(x => colors[x.Key.Value])
  46. .ToDictionary(x => x.Key, x => x.Value);
  47.  
  48. foreach (var dwarf in sorted)
  49. {
  50. var hatColor = dwarf.Key.Value;
  51. var name = dwarf.Key.Key;
  52. var physics = dwarf.Value;
  53.  
  54. Console.WriteLine("({0}) {1} <-> {2}", hatColor, name, physics);
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement