Advertisement
Guest User

HornetArmada

a guest
Oct 20th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class Activity
  7. {
  8. public int lastActivity { get; set; }
  9. public string LegName { get; set; }
  10. public Dictionary<string, ulong> STnC { get; set; }
  11.  
  12. }
  13.  
  14. class HornetArmada
  15. {
  16. static void Main()
  17. {
  18. int n = int.Parse(Console.ReadLine());
  19. List<Activity> data = new List<Activity>();
  20. Regex check = new Regex(@"(\d+) = (.+) -> (.+):(\d+)");
  21. for (int i = 0; i < n; i++)
  22. {
  23. Match match = check.Match(Console.ReadLine());
  24. int ActivityNum = int.Parse(match.Groups[1].Value);
  25. string LegionName = match.Groups[2].Value;
  26. string SoldierType = match.Groups[3].Value;
  27. ulong SoldierCount = ulong.Parse(match.Groups[4].Value);
  28. bool LegNameFree = true;
  29. for (int j = 0; j < data.Count; j++)
  30. {
  31. if (data[j].LegName == LegionName)
  32. {
  33. LegNameFree = false;
  34. if (data[j].lastActivity < ActivityNum)
  35. {
  36. data[j].lastActivity = ActivityNum;
  37. }
  38. if (data[j].STnC.ContainsKey(SoldierType))
  39. {
  40. data[j].STnC[SoldierType] += SoldierCount;
  41. }
  42. else
  43. {
  44. data[j].STnC.Add(SoldierType, SoldierCount);
  45. }
  46. }
  47. }
  48. if (LegNameFree)
  49. {
  50. Activity a = new Activity();
  51. a.lastActivity = ActivityNum;
  52. a.LegName = LegionName;
  53. a.STnC = new Dictionary<string, ulong>();
  54. a.STnC.Add(SoldierType, SoldierCount);
  55. data.Add(a);
  56. }
  57. }
  58. string[] command = Console.ReadLine().Split('\\');
  59. if (command.Length > 1)
  60. {
  61. int activity = int.Parse(command[0]);
  62. string type = command[1];
  63. Dictionary<string, ulong> res = new Dictionary<string, ulong>();
  64. foreach (var a in data)
  65. {
  66. if (a.STnC.ContainsKey(type) && a.lastActivity < activity)
  67. {
  68. res.Add(a.LegName, a.STnC[type]);
  69. }
  70. }
  71. foreach (var item in res.OrderByDescending(x => x.Value))
  72. {
  73. Console.WriteLine("{0} -> {1}", item.Key, item.Value);
  74. }
  75. }
  76. else
  77. {
  78. string type = command[0];
  79. Dictionary<string, ulong> res = new Dictionary<string, ulong>();
  80. foreach (var a in data)
  81. {
  82. if (a.STnC.ContainsKey(type))
  83. {
  84. res.Add(a.LegName, (ulong)a.lastActivity);
  85. }
  86. }
  87. foreach (var b in res.OrderByDescending(x => x.Value))
  88. {
  89. Console.WriteLine("{0} : {1}", b.Value, b.Key);
  90. }
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement