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;
- namespace CSharpPreparation
- {
- public class Soldiers
- {
- public long Activity { get; set; }
- public Dictionary<string, long> TypeAndCount { get; set; }
- }
- public class Program
- {
- private 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;
- }
- string[] outputFormat = Console.ReadLine().Split(new[] { '\\' }, StringSplitOptions.None);
- if (outputFormat.Length > 1)
- {
- long activity = long.Parse(outputFormat[0]);
- string type = outputFormat[1];
- Dictionary<string, long> found = new Dictionary<string, long>();
- foreach (var legion in legions)
- {
- if (legion.Value.Activity < activity)
- {
- foreach (var soldier in legion.Value.TypeAndCount)
- {
- if (soldier.Key == type)
- {
- found.Add(legion.Key, soldier.Value);
- }
- }
- }
- }
- foreach (var item in found.OrderByDescending(x => x.Value))
- {
- Console.WriteLine($"{item.Key} -> {item.Value}");
- }
- }
- else
- {
- var foundWithType = legions.Where(x => x.Value.TypeAndCount.Keys.Contains(outputFormat[0]));
- foreach (var soldier in foundWithType.OrderByDescending(x => x.Value.Activity))
- {
- Console.WriteLine($"{soldier.Value.Activity} : {soldier.Key}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement