Advertisement
paykova

Snowwhite

Feb 26th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 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. namespace _04P.Snowwhite
  7. {
  8. public class Snowwhite
  9. {
  10. public static void Main()
  11. {
  12. Solution1();
  13. //Solution2();
  14. }
  15. private static void Solution2()
  16. {
  17. var data = new Dictionary<string, Dictionary<string, int>>();
  18.  
  19. string input = Console.ReadLine();
  20.  
  21. while (input != "Once upon a time")
  22. {
  23. var dwarfInfo = input.Split("<:> ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
  24. string color = dwarfInfo[1];
  25. string name = dwarfInfo[0];
  26. int physics = int.Parse(dwarfInfo[2]);
  27. if (!data.ContainsKey(color))
  28. {
  29. data.Add(color, new Dictionary<string, int>());
  30. data[color][name] = physics;
  31. }
  32. else if (!data[color].ContainsKey(name))
  33. {
  34. data[color].Add(name, physics);
  35. }
  36. if (data[color][name] < physics)
  37. {
  38. data[color][name] = physics;
  39. }
  40. input = Console.ReadLine();
  41. }
  42. foreach (var color in data.OrderByDescending(x => x.Value.Values.Max()).ThenByDescending(x => x.Value.Count()))
  43. {
  44. var dwarfs = color.Value;
  45.  
  46. foreach (var dwarf in dwarfs)
  47. {
  48. Console.Write($"({color.Key}) ");
  49. Console.WriteLine($"{dwarf.Key} <-> {dwarf.Value}");
  50. }
  51. }
  52. }
  53. private static void Solution1()
  54. {
  55. string text = Console.ReadLine();
  56.  
  57. Dictionary<string, Dictionary<string, int>> dict = new Dictionary<string, Dictionary<string, int>>();
  58.  
  59. while (text != "Once upon a time")
  60. {
  61. string[] input = text
  62. .Split(new char[] { ',', ' ', '<', ':', '>' }, StringSplitOptions.RemoveEmptyEntries);
  63. string name = input[0].Trim();
  64. string color = input[1].Trim();
  65. int phys = int.Parse(input[2]);
  66. if (!dict.ContainsKey(color))
  67. {
  68. dict.Add(color, new Dictionary<string, int>());
  69. dict[color][name] = phys;
  70. }
  71. else if (!dict[color].ContainsKey(name))
  72. {
  73. dict[color].Add(name, phys);
  74. }
  75. if (dict[color][name] < phys)
  76. {
  77. dict[color][name] = phys;
  78. }
  79. text = Console.ReadLine();
  80. }
  81.  
  82.  
  83. foreach (var kvp in dict)
  84. {
  85.  
  86. foreach (var item in kvp.Value)
  87. {
  88.  
  89. Console.Write($"({kvp.Key}) ");
  90. Console.WriteLine($"{item.Key} <-> {item.Value}");
  91. }
  92. }
  93. }
  94.  
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement