Advertisement
Guest User

Untitled

a guest
Mar 18th, 2017
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. static void Main()
  2. {
  3. var legionParams = new Dictionary<string, Dictionary<string, long>>();
  4. var legionActivity = new Dictionary<string, long>();
  5.  
  6. int n = int.Parse(Console.ReadLine());
  7.  
  8. for (int i = 0; i < n; i++)
  9. {
  10. var inputInfo = Console.ReadLine();
  11.  
  12. var firstSplit = inputInfo.Split(new char[] { ' ', '=', '-', '>', ':' }, StringSplitOptions.RemoveEmptyEntries);
  13.  
  14. var lastActivity = long.Parse(firstSplit[0]);
  15. var legionName = firstSplit[1];
  16. var soldierType = firstSplit[2];
  17. var soldierCount = long.Parse(firstSplit[3]);
  18.  
  19.  
  20. if (!legionParams.ContainsKey(legionName))
  21. {
  22. legionParams[legionName] = new Dictionary<string, long>();
  23. legionActivity[legionName] = lastActivity;
  24. }
  25.  
  26. if (!legionParams[legionName].ContainsKey(soldierType))
  27. {
  28. legionParams[legionName][soldierType] = 0;
  29. }
  30.  
  31. legionParams[legionName][soldierType] += soldierCount;
  32.  
  33. if (legionActivity[legionName] < lastActivity)
  34. {
  35. legionActivity[legionName] = lastActivity;
  36. }
  37.  
  38.  
  39. }
  40.  
  41. var lastInput = Console.ReadLine().Split('\\');
  42.  
  43. if (lastInput.Length < 2)
  44. {
  45. var currentSoldierType = lastInput[0];
  46.  
  47. foreach (var legion in legionActivity.OrderByDescending(x => x.Value))
  48. {
  49. if (legionParams[legion.Key].ContainsKey(currentSoldierType))
  50. {
  51. Console.WriteLine($"{legion.Value} : {legion.Key}");
  52. }
  53. }
  54. }
  55. else
  56. {
  57. var currentActicity = long.Parse(lastInput[0]);
  58. var currentSoldierType = lastInput[1];
  59.  
  60. foreach (var legion in legionParams.OrderByDescending(x => x.Value[currentSoldierType]))
  61. {
  62. if (legionActivity[legion.Key] < currentActicity && legionParams[legion.Key].ContainsKey(currentSoldierType))
  63. {
  64. Console.WriteLine($"{legion.Key} -> {legionParams[legion.Key][currentSoldierType]}");
  65. }
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement