Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. namespace _04.CubicAssault
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. public class CubicAssault
  8. {
  9. public static void Main()
  10. {
  11. var inputLine = Console.ReadLine();
  12.  
  13. var result = new SortedDictionary<string, SortedDictionary<string, long>>();
  14.  
  15. while (inputLine != "Count em all")
  16. {
  17. var inputParams = inputLine.Split(new[] { '-', '>' });
  18.  
  19. var region = inputParams[0].Trim();
  20. var type = inputParams[1].Trim();
  21. var numberAsString = inputParams[2].Trim();
  22. var number = long.Parse(numberAsString);
  23.  
  24. if (!result.ContainsKey(region))
  25. {
  26. result.Add(region, new SortedDictionary<string, long>());
  27. result[region].Add("Black", 0L);
  28. result[region].Add("Red", 0L);
  29. result[region].Add("Green", 0L);
  30. }
  31.  
  32. result[region][type] += number;
  33. var isMoreThanMilion = result[region][type] / 1000000L;
  34.  
  35. if (type != "Black" && isMoreThanMilion > 0)
  36. {
  37. if (type == "Green")
  38. {
  39. result[region][type] = 0;
  40. result[region]["Red"] += isMoreThanMilion;
  41. isMoreThanMilion = result[region]["Red"] / 1000000L;
  42.  
  43. if (isMoreThanMilion > 0)
  44. {
  45. result[region]["Red"] = 0;
  46. result[region]["Black"] += isMoreThanMilion;
  47. }
  48. }
  49. else
  50. {
  51. result[region][type] = 0;
  52. result[region]["Black"] += isMoreThanMilion;
  53. }
  54. }
  55.  
  56. inputLine = Console.ReadLine();
  57. }
  58.  
  59. foreach (var region in result.OrderByDescending(x => x.Value["Black"]).ThenBy(x => x.Key.Length))
  60. {
  61. Console.WriteLine(region.Key);
  62.  
  63. foreach (var type in region.Value.OrderByDescending(x => x.Value))
  64. {
  65. Console.WriteLine($"-> {type.Key} : {type.Value}");
  66. }
  67. }
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement