Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace SnowWhite
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Dictionary<string, Dictionary<string, int>> dwarfData = new Dictionary<string, Dictionary<string, int>>();
  12.  
  13. while (true)
  14. {
  15. string input = Console.ReadLine();
  16.  
  17. if (input == "Once upon a time")
  18. {
  19. break;
  20. }
  21. string[] data = input.Split(" <:> ").ToArray();
  22.  
  23. DataEntry(data, dwarfData);
  24. }
  25.  
  26. foreach (var kvp in dwarfData.OrderByDescending(x => x.Value.Values.Max()).ThenByDescending(x=>x.Value.Keys.Count)) // .ThenByDescending(x=>x.Value.Keys.Count) никаква работа не върши, как да го накарам да преброй кой цвят са най-много?!
  27. {
  28. foreach (var nKvp in dwarfData[kvp.Key])
  29. {
  30. List<char> dwarfName = kvp.Key.ToList();
  31. dwarfName.RemoveAll(x => x < 58);
  32. string name = string.Join("", dwarfName.ToArray());
  33. string hatColor = nKvp.Key;
  34. int physics = nKvp.Value;
  35. Console.WriteLine($"({hatColor}) {name} <-> {physics}");
  36. }
  37. }
  38. }
  39.  
  40. static void DataEntry(string[] data, Dictionary<string, Dictionary<string, int>> dwarfData)
  41. {
  42. string name = data[0];
  43. string hatColour = data[1];
  44. int physics = int.Parse(data[2]);
  45. int index = 1;
  46.  
  47. if (!dwarfData.ContainsKey(name))
  48. {
  49. dwarfData.Add(name, new Dictionary<string, int>());
  50. dwarfData[name].Add(hatColour, physics);
  51. }
  52. else if (!dwarfData[name].ContainsKey(hatColour))
  53. {
  54. name = name + index;
  55. dwarfData.Add(name, new Dictionary<string, int>());
  56. dwarfData[name].Add(hatColour, physics);
  57. }
  58. else if (physics > dwarfData[name][hatColour])
  59. {
  60. dwarfData[name][hatColour] = physics;
  61. }
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement