Advertisement
social1986

Untitled

Oct 29th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04.Hornet_Armada
  6. {
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. var numberOfLegions = int.Parse(Console.ReadLine());
  12. var legions = new Dictionary<string, Dictionary<string, long>>();
  13. var legionActivity = new Dictionary<string, long>();
  14.  
  15. for (int i = 0; i < numberOfLegions; i++)
  16. {
  17. var currentArmy = Console.ReadLine()
  18. .Split(new string[] { " = ", " -> ", ":" }, StringSplitOptions.RemoveEmptyEntries)
  19. .ToArray();
  20. var currentAciticity = int.Parse(currentArmy[0]);
  21. var currentLegionName = currentArmy[1];
  22. var currentSoldierType = currentArmy[2];
  23. var currentSoldierCount = int.Parse(currentArmy[3]);
  24.  
  25. if (!legions.ContainsKey(currentLegionName))
  26. {
  27. legions.Add(currentLegionName, new Dictionary<string, long>());
  28. legionActivity.Add(currentLegionName, currentAciticity);
  29. }
  30.  
  31. if (currentAciticity > legionActivity[currentLegionName])
  32. {
  33. legionActivity[currentLegionName] = currentAciticity;
  34. }
  35.  
  36. if (!legions[currentLegionName].ContainsKey(currentSoldierType))
  37. {
  38. legions[currentLegionName].Add(currentSoldierType, 0);
  39. }
  40.  
  41. legions[currentLegionName][currentSoldierType] += currentSoldierCount;
  42. }
  43.  
  44. var command = Console.ReadLine().Split('\\');
  45.  
  46. if (command.Length > 1)
  47. {
  48. var activity = int.Parse(command[0]);
  49. var soldierType = command[1];
  50.  
  51. foreach (var legion in legions.Where(p => p.Value.ContainsKey(soldierType)).OrderByDescending(p => p.Value[soldierType]))
  52. {
  53. if (legionActivity[legion.Key] < activity)
  54. {
  55. Console.WriteLine($"{legion.Key} -> {legions[legion.Key][soldierType]}");
  56. }
  57. }
  58. }
  59. else
  60. {
  61. var soldierType = command[0];
  62.  
  63. foreach (var item in legionActivity.OrderByDescending(p => p.Value))
  64. {
  65. if (legions[item.Key].ContainsKey(soldierType))
  66. {
  67. Console.WriteLine($"{item.Value} : {item.Key}");
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement