MeGaDeTH_91

Cubic Assault

Feb 10th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1. namespace _04._Cubic_Assault
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. class Program
  8. {
  9. private const int Border = 1000000;
  10. static void Main(string[] args)
  11. {
  12. List<Region> regions = new List<Region>();
  13.  
  14. string command;
  15. while ((command = Console.ReadLine()) != "Count em all")
  16. {
  17. string[] currInput = command
  18. .Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries)
  19. .ToArray();
  20.  
  21. string currentRegion = currInput[0];
  22. string colorType = currInput[1];
  23. long typeCount = long.Parse(currInput[2]);
  24.  
  25. if (!regions.Any(x => x.Name == currentRegion))
  26. {
  27. Region newReg = new Region()
  28. {
  29. Name = currentRegion,
  30. Colors = new List<Color>(),
  31. BlackCount = 0
  32. };
  33. Color black = new Color()
  34. {
  35. ColorType = "Black",
  36. ColorCount = 0
  37. };
  38. Color red = new Color()
  39. {
  40. ColorType = "Red",
  41. ColorCount = 0
  42. };
  43. Color green = new Color()
  44. {
  45. ColorType = "Green",
  46. ColorCount = 0
  47. };
  48. newReg.Colors.Add(black);
  49. newReg.Colors.Add(red);
  50. newReg.Colors.Add(green);
  51. regions.Add(newReg);
  52. }
  53. var reg = regions.FirstOrDefault(x => x.Name == currentRegion);
  54. switch (colorType)
  55. {
  56. case "Black":
  57. reg.BlackCount += typeCount;
  58. reg.Colors.FirstOrDefault(x => x.ColorType == "Black").ColorCount += typeCount;
  59. break;
  60. case "Red":
  61. if (Math.Abs(typeCount) >= Border)
  62. {
  63. reg.Colors.FirstOrDefault(x => x.ColorType == "Black").ColorCount += typeCount / Border;
  64. reg.BlackCount += typeCount / Border;
  65. typeCount %= Border;
  66. }
  67. reg.Colors.FirstOrDefault(x => x.ColorType == "Red").ColorCount += typeCount;
  68. break;
  69. case "Green":
  70. if (Math.Abs(typeCount) >= Border)
  71. {
  72. reg.Colors.FirstOrDefault(x => x.ColorType == "Red").ColorCount += typeCount / Border;
  73. typeCount %= Border;
  74. }
  75. reg.Colors.FirstOrDefault(x => x.ColorType == "Green").ColorCount += typeCount;
  76. break;
  77. default:
  78. break;
  79. }
  80. }
  81. foreach (var reg in regions)
  82. {
  83. var redUpdate = reg.Colors.FirstOrDefault(x => x.ColorType == "Red");
  84. var greenUpdate = reg.Colors.FirstOrDefault(x => x.ColorType == "Green");
  85. var blackUpdate = reg.Colors.FirstOrDefault(x => x.ColorType == "Black");
  86.  
  87. while (redUpdate.ColorCount >= Border || greenUpdate.ColorCount >= Border)
  88. {
  89. if (greenUpdate.ColorCount >= Border)
  90. {
  91. redUpdate.ColorCount += greenUpdate.ColorCount / Border;
  92. greenUpdate.ColorCount %= Border;
  93. }
  94. if (redUpdate.ColorCount >= Border)
  95. {
  96. blackUpdate.ColorCount += redUpdate.ColorCount / Border;
  97. reg.BlackCount += redUpdate.ColorCount / Border;
  98. redUpdate.ColorCount %= Border;
  99. }
  100. }
  101. }
  102.  
  103. foreach (var region in regions.OrderByDescending(x => x.BlackCount).ThenBy(x => x.Name.Length).ThenBy(x => x.Name))
  104. {
  105. Console.WriteLine($"{region.Name}");
  106. foreach (var color in region.Colors.OrderByDescending(x => x.ColorCount).ThenBy(x => x.ColorType))
  107. {
  108. Console.WriteLine($"-> {color.ColorType} : {color.ColorCount}");
  109. }
  110. }
  111. }
  112. public class Region
  113. {
  114. public string Name { get; set; }
  115.  
  116. public long BlackCount { get; set; }
  117.  
  118. public List<Color> Colors { get; set; }
  119. }
  120. public class Color
  121. {
  122. public string ColorType { get; set; }
  123. public long ColorCount { get; set; }
  124. }
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment