Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _5_04.HornetArmada
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Dictionary<string, Soldiers > legions = new Dictionary<string, Soldiers>();
  14.  
  15. var n = int.Parse(Console.ReadLine());
  16. for (int i = 0; i < n; i++)
  17. {
  18. var currLeg = Console.ReadLine().Split(new[] { '=', '-', '>', ':',' ' }, StringSplitOptions.RemoveEmptyEntries);
  19.  
  20. var lastActivity = long.Parse(currLeg[0]);
  21. var name = currLeg[1];
  22. var type = currLeg[2];
  23. var count = long.Parse(currLeg[3]);
  24.  
  25. if (!legions.ContainsKey(name))
  26. {
  27. legions[name] = new Soldiers();
  28. Dictionary<string, long> currTypeCount = new Dictionary<string, long>();
  29. legions[name].TypeAndCount = currTypeCount;
  30. legions[name].Activity = -1;
  31. }
  32. if (!legions[name].TypeAndCount.ContainsKey(type))
  33. {
  34. legions[name].TypeAndCount[type] = 0;
  35. }
  36. if (legions[name].Activity < lastActivity)
  37. legions[name].Activity = lastActivity;
  38.  
  39. legions[name].TypeAndCount[type] += count;
  40.  
  41. }
  42.  
  43. var command = Console.ReadLine();
  44. Regex firstType = new Regex(@"(\d+)\\(.+)");
  45.  
  46. if (firstType.IsMatch(command))
  47. {
  48. var match = firstType.Match(command);
  49.  
  50. var activity = long.Parse(match.Groups[1].Value);
  51. var type = match.Groups[2].Value;
  52.  
  53. var belowType = legions.Where(x => x.Value.Activity < activity).ToDictionary(x => x.Key, y => y.Value);
  54. if (belowType.Count > 0)
  55. {
  56. foreach (var groupName in belowType.OrderByDescending(x => x.Value.TypeAndCount[type]).ToDictionary(x => x.Key, y => y.Value))
  57. {
  58. foreach (var item in groupName.Value.TypeAndCount)
  59. {
  60. if (item.Key == type)
  61. {
  62. Console.WriteLine($"{groupName.Key} -> {item.Value}");
  63. }
  64. }
  65. }
  66. }
  67. }
  68. else
  69. {
  70. var type = command;
  71.  
  72. foreach (var groupName in legions.OrderByDescending(x => x.Value.Activity).ToDictionary(x => x.Key, y => y.Value))
  73. {
  74. foreach (var item in groupName.Value.TypeAndCount)
  75. {
  76. if (item.Key == type)
  77. {
  78. Console.WriteLine($"{groupName.Value.Activity} : {groupName.Key}");
  79. }
  80. }
  81. }
  82.  
  83.  
  84. }
  85.  
  86.  
  87. }
  88. }
  89. public class Soldiers
  90. {
  91. public long Activity { get; set; }
  92. public Dictionary<string, long> TypeAndCount { get; set; }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement