Advertisement
YavorGrancharov

Hornet_Armada

Aug 17th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Hornet_Armada
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.  
  15.             Dictionary<string, Dictionary<string, long>> legionParams = new Dictionary<string, Dictionary<string, long>>();
  16.             Dictionary<string, long> legionActivity = new Dictionary<string, long>();
  17.  
  18.             for (int i = 0; i < n; i++)
  19.             {
  20.                 string input = Console.ReadLine();
  21.  
  22.                 string[] tokens = input
  23.                     .Split(new string[] { "=", " ", "->", ":"}, StringSplitOptions.RemoveEmptyEntries);
  24.  
  25.                 int lastActivity = int.Parse(tokens[0]);
  26.                 string legionName = tokens[1];
  27.                 string soldierType = tokens[2];
  28.                 long soldierCount = long.Parse(tokens[3]);
  29.  
  30.                 if (!legionParams.ContainsKey(legionName))
  31.                 {
  32.                     legionParams.Add(legionName, new Dictionary<string, long>());
  33.                     legionActivity[legionName] = lastActivity;
  34.                 }
  35.  
  36.                 if (!legionParams[legionName].ContainsKey(soldierType))
  37.                 {
  38.                     legionParams[legionName][soldierType] = 0;
  39.                 }
  40.                 legionParams[legionName][soldierType] += soldierCount;
  41.  
  42.                 if (legionActivity[legionName] < lastActivity)
  43.                 {
  44.                     legionActivity[legionName] = lastActivity;
  45.                 }
  46.             }
  47.  
  48.             string[] secondInput = Console.ReadLine().Split('\\');
  49.  
  50.             if (secondInput.Length < 2)
  51.             {
  52.                 string currentSoldierType = secondInput[0];
  53.  
  54.                 foreach (var legion in legionActivity.OrderByDescending(x => x.Value))
  55.                 {
  56.                     if (legionParams[legion.Key].ContainsKey(currentSoldierType))
  57.                     {
  58.                         Console.WriteLine($"{legion.Value} : {legion.Key}");
  59.                     }
  60.                 }
  61.             }
  62.             else
  63.             {
  64.                 var currentActivity = long.Parse(secondInput[0]);
  65.                 var currentSoldierType = secondInput[1];
  66.  
  67.                 foreach (var legion in legionParams
  68.                     .Where(x => x.Value.ContainsKey(currentSoldierType))
  69.                     .OrderByDescending(x => x.Value[currentSoldierType]))
  70.                 {
  71.                     if (legionActivity[legion.Key] < currentActivity && legionParams[legion.Key].ContainsKey(currentSoldierType))
  72.                     {
  73.                         Console.WriteLine($"{legion.Key} -> {legionParams[legion.Key][currentSoldierType]}");
  74.                     }
  75.                 }
  76.             }  
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement