Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _04.Hornet_Armada
- {
- public class Program
- {
- public static void Main()
- {
- var numberOfLegions = int.Parse(Console.ReadLine());
- var legions = new Dictionary<string, Dictionary<string, long>>();
- var legionActivity = new Dictionary<string, long>();
- for (int i = 0; i < numberOfLegions; i++)
- {
- var currentArmy = Console.ReadLine()
- .Split(new string[] { " = ", " -> ", ":" }, StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- var currentAciticity = int.Parse(currentArmy[0]);
- var currentLegionName = currentArmy[1];
- var currentSoldierType = currentArmy[2];
- var currentSoldierCount = int.Parse(currentArmy[3]);
- if (!legions.ContainsKey(currentLegionName))
- {
- legions.Add(currentLegionName, new Dictionary<string, long>());
- legionActivity.Add(currentLegionName, currentAciticity);
- }
- if (currentAciticity > legionActivity[currentLegionName])
- {
- legionActivity[currentLegionName] = currentAciticity;
- }
- if (!legions[currentLegionName].ContainsKey(currentSoldierType))
- {
- legions[currentLegionName].Add(currentSoldierType, 0);
- }
- legions[currentLegionName][currentSoldierType] += currentSoldierCount;
- }
- var command = Console.ReadLine().Split('\\');
- if (command.Length > 1)
- {
- var activity = int.Parse(command[0]);
- var soldierType = command[1];
- foreach (var legion in legions.Where(p => p.Value.ContainsKey(soldierType)).OrderByDescending(p => p.Value[soldierType]))
- {
- if (legionActivity[legion.Key] < activity)
- {
- Console.WriteLine($"{legion.Key} -> {legions[legion.Key][soldierType]}");
- }
- }
- }
- else
- {
- var soldierType = command[0];
- foreach (var item in legionActivity.OrderByDescending(p => p.Value))
- {
- if (legions[item.Key].ContainsKey(soldierType))
- {
- Console.WriteLine($"{item.Value} : {item.Key}");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement