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;
- using System.Threading.Tasks;
- using System.Text.RegularExpressions;
- namespace ConsoleApp76
- {
- class Legion
- {
- public Legion(string legionName, long activity)
- {
- this.LegionName = legionName;
- this.Activity = activity;
- }
- public string LegionName { get; set; }
- public long Activity { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- var dict = new Dictionary<Legion, Dictionary<string, long>>();
- string validation = @"^[^=\->:\s]*$";
- int number = int.Parse(Console.ReadLine());
- for (int i = 0; i < number; i++)
- {
- string input = Console.ReadLine();
- string[] split = input.Split(new char[] { ' ', '=', '-', '>', ':' }, StringSplitOptions.RemoveEmptyEntries);
- long lastActivity = long.Parse(split[0]);
- string legionName = split[1];
- string soldierType = split[2];
- long soldierCount = long.Parse(split[3]);
- Regex check = new Regex(validation);
- if (!check.IsMatch(legionName) || !check.IsMatch(soldierType))
- {
- continue;
- }
- if (!dict.Any(x => x.Key.LegionName == legionName))
- {
- Legion legion = new Legion(legionName, lastActivity);
- dict.Add(legion, new Dictionary<string, long>());
- dict[legion].Add(soldierType, soldierCount);
- }
- else
- {
- foreach (var item in dict.Where(x => x.Key.LegionName == legionName))
- {
- if (item.Key.Activity < lastActivity)
- {
- item.Key.Activity = lastActivity;
- }
- }
- var index = dict.Keys.FirstOrDefault(x => x.LegionName == legionName);
- if (dict[index].ContainsKey(soldierType))
- {
- dict[index][soldierType] += soldierCount;
- }
- else
- {
- dict[index][soldierType] = soldierCount;
- }
- }
- }
- string[] format = Console.ReadLine().Split('\\');
- if (format.Length == 2)
- {
- long activity = long.Parse(format[0]);
- string soldierType = format[1];
- foreach (var item in dict
- .Where(x => x.Value.ContainsKey(soldierType))
- .OrderByDescending(x => x.Value[soldierType]))
- {
- if (item.Key.Activity < activity)
- {
- Console.WriteLine($"{item.Key.LegionName} -> {item.Value[soldierType]}");
- }
- }
- }
- else
- {
- string soldierType = format[0];
- foreach (var item in dict.OrderByDescending(x => x.Key.Activity))
- {
- foreach (var z in item.Value.Where(x => x.Key == soldierType))
- {
- Console.WriteLine($"{item.Key.Activity} : {item.Key.LegionName}");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement