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;
- public class Activity
- {
- public int lastActivity { get; set; }
- public string LegName { get; set; }
- public Dictionary<string, ulong> STnC { get; set; }
- }
- class HornetArmada
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- List<Activity> data = new List<Activity>();
- Regex check = new Regex(@"(\d+) = (.+) -> (.+):(\d+)");
- for (int i = 0; i < n; i++)
- {
- Match match = check.Match(Console.ReadLine());
- int ActivityNum = int.Parse(match.Groups[1].Value);
- string LegionName = match.Groups[2].Value;
- string SoldierType = match.Groups[3].Value;
- ulong SoldierCount = ulong.Parse(match.Groups[4].Value);
- bool LegNameFree = true;
- for (int j = 0; j < data.Count; j++)
- {
- if (data[j].LegName == LegionName)
- {
- LegNameFree = false;
- if (data[j].lastActivity < ActivityNum)
- {
- data[j].lastActivity = ActivityNum;
- }
- if (data[j].STnC.ContainsKey(SoldierType))
- {
- data[j].STnC[SoldierType] += SoldierCount;
- }
- else
- {
- data[j].STnC.Add(SoldierType, SoldierCount);
- }
- }
- }
- if (LegNameFree)
- {
- Activity a = new Activity();
- a.lastActivity = ActivityNum;
- a.LegName = LegionName;
- a.STnC = new Dictionary<string, ulong>();
- a.STnC.Add(SoldierType, SoldierCount);
- data.Add(a);
- }
- }
- string[] command = Console.ReadLine().Split('\\');
- if (command.Length > 1)
- {
- int activity = int.Parse(command[0]);
- string type = command[1];
- Dictionary<string, ulong> res = new Dictionary<string, ulong>();
- foreach (var a in data)
- {
- if (a.STnC.ContainsKey(type) && a.lastActivity < activity)
- {
- res.Add(a.LegName, a.STnC[type]);
- }
- }
- foreach (var item in res.OrderByDescending(x => x.Value))
- {
- Console.WriteLine("{0} -> {1}", item.Key, item.Value);
- }
- }
- else
- {
- string type = command[0];
- Dictionary<string, ulong> res = new Dictionary<string, ulong>();
- foreach (var a in data)
- {
- if (a.STnC.ContainsKey(type))
- {
- res.Add(a.LegName, (ulong)a.lastActivity);
- }
- }
- foreach (var b in res.OrderByDescending(x => x.Value))
- {
- Console.WriteLine("{0} : {1}", b.Value, b.Key);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement