Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace _5_04.HornetArmada
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, Soldiers > legions = new Dictionary<string, Soldiers>();
- var n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- var currLeg = Console.ReadLine().Split(new[] { '=', '-', '>', ':',' ' }, StringSplitOptions.RemoveEmptyEntries);
- var lastActivity = long.Parse(currLeg[0]);
- var name = currLeg[1];
- var type = currLeg[2];
- var count = long.Parse(currLeg[3]);
- if (!legions.ContainsKey(name))
- {
- legions[name] = new Soldiers();
- Dictionary<string, long> currTypeCount = new Dictionary<string, long>();
- legions[name].TypeAndCount = currTypeCount;
- legions[name].Activity = -1;
- }
- if (!legions[name].TypeAndCount.ContainsKey(type))
- {
- legions[name].TypeAndCount[type] = 0;
- }
- if (legions[name].Activity < lastActivity)
- legions[name].Activity = lastActivity;
- legions[name].TypeAndCount[type] += count;
- }
- var command = Console.ReadLine();
- Regex firstType = new Regex(@"(\d+)\\(.+)");
- if (firstType.IsMatch(command))
- {
- var match = firstType.Match(command);
- var activity = long.Parse(match.Groups[1].Value);
- var type = match.Groups[2].Value;
- var belowType = legions.Where(x => x.Value.Activity < activity).ToDictionary(x => x.Key, y => y.Value);
- if (belowType.Count > 0)
- {
- foreach (var groupName in belowType.OrderByDescending(x => x.Value.TypeAndCount[type]).ToDictionary(x => x.Key, y => y.Value))
- {
- foreach (var item in groupName.Value.TypeAndCount)
- {
- if (item.Key == type)
- {
- Console.WriteLine($"{groupName.Key} -> {item.Value}");
- }
- }
- }
- }
- }
- else
- {
- var type = command;
- foreach (var groupName in legions.OrderByDescending(x => x.Value.Activity).ToDictionary(x => x.Key, y => y.Value))
- {
- foreach (var item in groupName.Value.TypeAndCount)
- {
- if (item.Key == type)
- {
- Console.WriteLine($"{groupName.Value.Activity} : {groupName.Key}");
- }
- }
- }
- }
- }
- }
- public class Soldiers
- {
- public long Activity { get; set; }
- public Dictionary<string, long> TypeAndCount { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement