Advertisement
North_Point

04. Hornet Armada

Dec 27th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.59 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 _04.Hornet_Armada
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var n = long.Parse(Console.ReadLine());
  14.  
  15.             var firstDic = new Dictionary<string,Dictionary<string,long>>();
  16.             var secondDid = new Dictionary<string, long>();
  17.             for (int i = 0; i < n; i++)
  18.             {
  19.                 var tokens = Console.ReadLine().Split(new char[] { '=', '-', '>', ':', ' ' }, StringSplitOptions.RemoveEmptyEntries);
  20.                 var lastActivity =long.Parse(tokens[0]);
  21.                 var legionName = tokens[1];
  22.                 var soldierType = tokens[2];
  23.                 var soldierCount = long.Parse(tokens[3]);
  24.  
  25.                 if (!firstDic.ContainsKey(legionName))
  26.                 {
  27.                     firstDic.Add(legionName, new Dictionary<string, long>());
  28.                     secondDid.Add(legionName, lastActivity);
  29.                 }
  30.                 if (!firstDic[legionName].ContainsKey(soldierType))
  31.                 {
  32.                     firstDic[legionName][soldierType] = 0;
  33.                 }
  34.                 if (secondDid[legionName] < lastActivity)
  35.                 {
  36.                     secondDid[legionName] = lastActivity;
  37.                 }
  38.                 firstDic[legionName][soldierType] += soldierCount;
  39.                
  40.             }
  41.             var command = Console.ReadLine().Split('\\');
  42.             if (command.Length == 1)
  43.             {
  44.                 foreach (var item in secondDid.OrderByDescending(x => x.Value))
  45.                 {
  46.                     if (firstDic[item.Key].ContainsKey(command[0]))
  47.                     {
  48.                         Console.WriteLine(item.Value + " : " + item.Key);
  49.                     }
  50.                 }
  51.             }
  52.             else
  53.             {
  54.                 long searchActivity = long.Parse(command[0]);
  55.                 var searchName = command[1];
  56.  
  57.                 foreach (var item in firstDic.Where(l => l.Value.ContainsKey(searchName))
  58.                     .OrderByDescending(l => l.Value[searchName]))
  59.                 {
  60.                     if (secondDid[item.Key] < searchActivity)
  61.                     {
  62.                         Console.WriteLine("{0} -> {1}",item.Key,item.Value[searchName]);
  63.                     }
  64.                 }
  65.  
  66.             }
  67.          
  68.             //  foreach (var item in firstDic)
  69.             //  {
  70.             //      Console.WriteLine(item.Key);
  71.             //  }
  72.  
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement