static void Main() { var pattern = new Regex(@"^(?<activity>\d+)\s+=\s+(?<legionName>[^=->:\s]+)\s+->\s+(?<soldierType>[^=->:\s]+)\s*:\s*(?<soldierCount>\d+)$"); var Legions = new Dictionary <string, Legion>(); for (int i = int.Parse(ReadLine()); i > 0; i--) { var input = ReadLine(); if (pattern.IsMatch(input)) { var matches = pattern.Match(input); var activity = long.Parse(matches.Groups["activity"].Value); var legionName = matches.Groups["legionName"].Value; var soldierType = matches.Groups["soldierType"].Value; var soldierCount = long.Parse(matches.Groups["soldierCount"].Value); if (Legions.ContainsKey(legionName)) { Legions[legionName].AddSoldiers(soldierType, soldierCount, activity); } else { Legions[legionName] = new Legion(soldierType, soldierCount, activity); } } } var command = ReadLine(); if (command.Contains("\\")) { long activity = long.Parse(command.Split('\\')[0]); string soldierType = command.Split('\\')[1]; if (Legions.Any(l => l.Value.SoldierTypeCount.ContainsKey(soldierType))) { var querryResult = Legions .Where(l => l.Value.Activity < activity && l.Value.SoldierTypeCount.ContainsKey(soldierType)) .OrderByDescending(s => s.Value.SoldierTypeCount[soldierType]) .ToDictionary(k => k.Key, v => v.Value); foreach (var legion in querryResult) { WriteLine($"{legion.Key} -> {legion.Value.SoldierTypeCount[soldierType]}"); } } } else { var querryResult = Legions .Where(l => l.Value.SoldierTypeCount.ContainsKey(command)) .OrderByDescending(l => l.Value.Activity) .ToDictionary(k => k.Key, v => v.Value); foreach (var legion in querryResult) { WriteLine($"{legion.Value.Activity} : {legion.Key}"); } } }
public void Setup() { carlos = new Comun(); mabel = new Abuelo(50); juana = new Necios(); maquillaje = new Maquillaje(); tiernos = new Tiernos(); terrorificos = new Terrorificos(); maria = new Niños(maquillaje, tiernos, 4, 16); juan = new Niños(maquillaje, tiernos, 6, 3); tomas = new Niños(maquillaje, terrorificos, 2, 14); camila = new Niños(maquillaje, terrorificos, 4, 5); niños = new List <Niños>(); niños.Add(maria); niños.Add(juan); niños.Add(tomas); niños.Add(camila); miembros = new List <LegionDeTerror> { maria, juan, camila }; legion = new Legion(niños); legiones = new LegionesDeLegiones(new List <LegionDeTerror>() { legion, tomas }); miembros.Add(tomas); }
public void Setup() { abuelo = new Abuelo(); necio = new Necio(); comun = new Comun(); maqui = new Maquillaje(); tierno = new Traje_Tierno(); terror = new Traje_Terrorifico(); mary = new Niño(maqui, tierno, 16); jony = new Niño(maqui, terror, 0); romo = new Niño(maqui, terror, 5); flor = new Niño(maqui, terror, 100); niños = new List <Asustador>() { mary, jony, romo }; legion = new Legion(niños); legionDeLegiones = new Legion(new List <Asustador>() { legion, flor }); niños.Add(flor); }
/// <summary> /// Creates and returns a new legion. /// Instantiates a new game object. /// If successful, removes the cohorts from the city's units /// and adds the legion. /// </summary> public Legion FormLegion(List <Cohort> cohorts) { if (cohorts.Count >= CombinedUnitConstants.LEGION_SIZE_LOWER_BOUND && cohorts.Count <= CombinedUnitConstants.LEGION_SIZE_UPPER_BOUND) { legionCount++; Legion legion = Instantiate(emptyUnitPrefab).AddComponent <Legion>(); legion.unitName = Utilities.instance.CountToOrdinal(legionCount) + " Legion"; legion.units = cohorts; foreach (Cohort cohort in cohorts) { currentCity.occupyingUnits.Remove(cohort); } currentCity.AddOccupyingUnits(new List <Unit>() { legion }); return(legion); } else { return(null); } }
public void TestLaCreacionNoFallaLaLegionAsustaAUnaPersonaYLaLegionAñadeIntegrantes() { Assert.True(legion1.Count >= 2); Legion legion = new Legion(legion1); legion.asustar(adultoComun); legion.añadirIntegrantes(legion2); }
public Legion CreateLegion(Legion legion) { int id = _db.ExecuteScalar <int> (@"INSERT INTO legion (img, primarch, legionHomeWorld, legionStory, isLoyal, name) VALUES (@Img, @Primarch, @LegionHomeWorld, @LegionStory, @IsLoyal, @Name); SELECT LAST_INSERT_ID();", legion); legion.Id = id; return(legion); }
public void Setup() { Pepe = new Niño(5, "Tierno"); Juan = new Niño(4, "Terrorificos"); PapáJuan = new Adulto(30, 5, "Comun"); PapáPepe = new Adulto(25, 3, "Abuelo"); LegionTerror = new Legion(Pepe, Juan); }
public static int IsExistingType(Legion legion, SoldierType st) { for (int i = 0; i < legion.SoldierTypes.Count; i++) { if (legion.SoldierTypes[i].Name.Equals(st.Name)) { return(i); } } return(-1); }
static void Main() { long n = long.Parse(Console.ReadLine()); List <Legion> listOfLegions = new List <Legion>(); for (int i = 0; i < n; i++) { var data = Console.ReadLine() .Split(new string[] { " = ", " -> ", ":" }, StringSplitOptions.RemoveEmptyEntries); long activity = long.Parse(data[0]); string name = data[1]; string type = data[2]; long count = long.Parse(data[3]); bool alreadyThere = false; foreach (var singleLegion in listOfLegions) { if (singleLegion.Name == name) { alreadyThere = true; if (singleLegion.LastActivity < activity) { singleLegion.LastActivity = activity; } if (singleLegion.SoldiersTypeAndCount.ContainsKey(type)) { singleLegion.SoldiersTypeAndCount[type] += count; } else { singleLegion.SoldiersTypeAndCount.Add(type, count); } } } if (!alreadyThere) { Legion legion = new Legion(); legion.LastActivity = activity; legion.Name = name; legion.SoldiersTypeAndCount = new Dictionary <string, long>(); legion.SoldiersTypeAndCount.Add(type, count); listOfLegions.Add(legion); } } string output = Console.ReadLine(); if (output.Contains("\\")) { PrintSoldiersAndActivity(output, listOfLegions); } else { PrintAllSoldiersOfTHisType(listOfLegions, output); } }
public void Verify_Roman_Numerals() { // Arrange var ch = 'X'; // Act var result = Legion.CountOccurrences(1, 2660, ch); // Assert Assert.AreEqual(3977, result); }
public ActionResult <Legion> Post([FromBody] Legion legion) { try { return(Ok(_repository.CreateLegion(legion))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public static int IsExistingLegion(List <Legion> legions, Legion leg) { for (int i = 0; i < legions.Count; i++) { if (legions[i].Name.Equals(leg.Name)) { return(i); } } return(-1); }
public void Legion_WorkersCount_Correct() { int s = 0; const int count = 4; var legion = new Legion(count, () => { Interlocked.Increment(ref s); }); legion.Do(); Assert.AreEqual(count, s); }
public static void HornetArmada() { var legions = new List <Legion>(); Regex regex = new Regex(@"^(?<activity>\d+)( = )(?<legionName>[^=->:\s]+)( -> )(?<soldierType>[^=->:\s]+)(:)(?<soldierCount>\d+)$"); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string input = Console.ReadLine(); if (!(regex.IsMatch(input))) { continue; } ulong activity = ulong.Parse(regex.Match(input).Groups["activity"].Value); string legionName = regex.Match(input).Groups["legionName"].Value; string soldierType = regex.Match(input).Groups["soldierType"].Value; ulong soldierCount = ulong.Parse(regex.Match(input).Groups["soldierCount"].Value); SoldierType st = new SoldierType(soldierCount, soldierType); Legion legion = new Legion(legionName, activity); if (IsExistingLegion(legions, legion) != -1) { legion = legions[IsExistingLegion(legions, legion)]; if (activity > legion.Activity) { legion.Activity = activity; } int flag = IsExistingType(legion, st); if (flag != -1) { legion.SoldierTypes[flag].Count += st.Count; } else { legion.SoldierTypes.Add(st); } legion.CountOfSoldiers += soldierCount; } else { legion.SoldierTypes.Add(st); legion.CountOfSoldiers += soldierCount; legions.Add(legion); } } string outputCommand = Console.ReadLine(); Output(outputCommand, legions); }
static void AddNewLegion() { var newLegion = new Legion(); newLegion.LegionName = name; newLegion.LastActivity = activity; newLegion.Soldiers = new List <LegionTypes>(); var newType = new LegionTypes(); newType.SoldierType = type; newType.SoldierCount = count; newLegion.Soldiers.Add(newType); hornetLegions.Add(newLegion); }
public void TestGetAllSlowerThanGivenSpeedWorksSuccessfuly() { var legion = new Legion(); for (int i = 0; i < 20; i++) { legion.Create(new Kamikaze(i, i * 2)); } var fasterEnemies = legion.GetSlower(9); Assert.IsTrue(fasterEnemies.All(e => e.AttackSpeed < 9)); }
public void GetOrderedByHealth_1000_Enemies() { IArmy legion = new Legion(); Random rnd = new Random(); Stopwatch sw = new Stopwatch(); for (int i = 0; i < 1_000; i++) { legion.Create(new Biomechanoid(i + 1, rnd.Next(500))); } sw.Start(); legion.GetOrderedByHealth(); sw.Stop(); Assert.IsTrue(sw.ElapsedMilliseconds <= 100); }
static void Main() { var legionsData = new List<Legion>(); long count = long.Parse(Console.ReadLine()); string input = Console.ReadLine(); for (int i = 0; i < count; i++) { string[] tokens = input .Split(new[] { "->", "=", ":" }, StringSplitOptions.None); int lastActivity = int.Parse(tokens[0].Trim()); string legionName = tokens[1].Trim(); string soildierType = tokens[2].Trim(); long soiderCount = long.Parse(tokens[3].Trim()); bool legionIsAlreadyRegistered = CheckIsThereLegionWithSameName(legionsData, legionName); if (legionIsAlreadyRegistered) { legionsData = UpdateLegionData(lastActivity, legionName, soildierType, soiderCount, legionsData); } else { var soilderAndCount = new Dictionary<string, long>(); soilderAndCount[soildierType] = soiderCount; Legion notRegistered = new Legion { legionName = legionName, lastActivity = lastActivity, typeAndCountSoilder = soilderAndCount }; legionsData.Add(notRegistered); } input = Console.ReadLine(); } ReadCommandForResultAndPrintResult(legionsData, input); }
static void AddLegion(Dictionary <string, Legion> legions, string legionName, string soldierType, int soldiersCount, int lastActivity) { if (!legions.ContainsKey(legionName)) { legions[legionName] = new Legion(legionName); } if (!legions[legionName].Soldiers.ContainsKey(soldierType)) { legions[legionName].Soldiers[soldierType] = 0; } legions[legionName].Soldiers[soldierType] += soldiersCount; if (legions[legionName].LastActivity < lastActivity) { legions[legionName].LastActivity = lastActivity; } }
IEnumerator CreateEnemy(Legion m_EnemyPrefab, List <GameObject> houseTransform) { yield return(new WaitForSeconds(m_EnemyPrefab.Time - 2)); Instantiate(WarnPrefab, m_EnemyPrefab.m_LegionPosition.position, m_EnemyPrefab.m_LegionPosition.rotation); yield return(new WaitForSeconds(2)); GameObject legion = Instantiate(EnemyLegionPrefab, m_EnemyPrefab.m_LegionPosition.position, m_EnemyPrefab.m_LegionPosition.rotation) as GameObject; EnemyManager enemyManager = legion.GetComponent <EnemyManager>(); enemyManager.Init(m_EnemyPrefab.Number, m_EnemyPrefab.LegionPrefeb); enemyManager.m_Instance = legion; enemyManager.Setup(houseTransform, ref enemines); EnemyCreateCount++; if (EnemyCreateCount == m_EnemyPrefabs.Length) { EnemyCreateFinish = true; } }
public void SetupLegionEditor(Legion l) { if (l.ShortName == null) { l.ShortName = "NAME"; } if (l.Name == null) { l.Name = "Legion name"; } if (l.Description == null) { l.Description = "This is your legion description."; } txtnewlegionshortname.Text = l.ShortName; txtnewlegiondescription.Text = l.Description; txtnewlegiontitle.Text = l.Name; lgn_create.BringToFront(); }
public void Setup() { traje1 = new Traje("Winnie Poo", "Tierno"); traje2 = new Traje("SAW", "Terrorifico"); niño1 = new Niño(traje1, 10); niño2 = new Niño(traje2, 8); niño3 = new Niño(traje1, 5); abuelo1 = new Abuelo(); adulto1 = new AdultoComun(); adulto2 = new AdultoNecio(); legion1 = new Legion(new List <Malevolo> { niño1, niño2 }); legion2 = new Legion(new List <Malevolo> { niño2, niño3 }); legionLegion2 = new Legion(new List <Malevolo> { legion1, legion2 }); barrioNorte = new Barrios(new List <Niño> { niño1, niño2, niño3 }); }
public void ShowLegionInfo(Legion lgn) { lgn_view.BringToFront(); lblegiontitle.Text = $"[{lgn.ShortName}] {lgn.Name}"; lbdescription.Text = lgn.Description; if (lgn.Publicity == LegionPublicity.PublicInviteOnly || lgn.Publicity == LegionPublicity.UnlistedInviteOnly) { btnjoinlegion.Hide(); } banner.BackColor = GetColor(lgn.BannerColor); ServerManager.SendMessage("legion_get_users", JsonConvert.SerializeObject(lgn)); btnleavelegion.Hide(); if (SaveSystem.CurrentSave.CurrentLegions.Contains(lgn.ShortName)) { btnjoinlegion.Hide(); btnleavelegion.Show(); } }
private void InitializeButtons() { cancelCombineButton.onClick.AddListener(() => { EventManager.instance.fireDefaultSelectedEvent(); }); confirmCombineButton.onClick.AddListener(() => { if (UnitListIsValid()) { switch (selectedUnits[0]) { case Troop t: Century century = UnitCombiner.instance.FormCentury(new SelectedUnits <Troop>(selectedUnits).units); if (century != null) { selectedUnits.Clear(); } else { this.DeselectAllUnits(); } break; case Century c: Cohort cohort = UnitCombiner.instance.FormCohort(new SelectedUnits <Century>(selectedUnits).units); if (cohort != null) { selectedUnits.Clear(); } else { this.DeselectAllUnits(); } break; case Cohort c: Legion legion = UnitCombiner.instance.FormLegion(new SelectedUnits <Cohort>(selectedUnits).units); if (legion != null) { selectedUnits.Clear(); } else { this.DeselectAllUnits(); } break; default: break; } InitializeAvailableTroopsScrollview(); InitializeSelectedTroopsScrollview(); } else { this.DeselectAllUnits(); InitializeAvailableTroopsScrollview(); InitializeSelectedTroopsScrollview(); }; }); }
internal static void CityProduction(City city) { if (city == null || city.Size == 0 || city.Tile == null) { return; } Player player = Game.GetPlayer(city.Owner); IProduction production = null; // Create 2 defensive units per city if (player.HasAdvance <LaborUnion>()) { if (city.Tile.Units.Count(x => x is MechInf) < 2) { production = new MechInf(); } } else if (player.HasAdvance <Conscription>()) { if (city.Tile.Units.Count(x => x is Riflemen) < 2) { production = new Riflemen(); } } else if (player.HasAdvance <Gunpowder>()) { if (city.Tile.Units.Count(x => x is Musketeers) < 2) { production = new Musketeers(); } } else if (player.HasAdvance <BronzeWorking>()) { if (city.Tile.Units.Count(x => x is Phalanx) < 2) { production = new Phalanx(); } } else { if (city.Tile.Units.Count(x => x is Militia) < 2) { production = new Militia(); } } // Create city improvements if (production == null) { if (!city.HasBuilding <Barracks>()) { production = new Barracks(); } else if (player.HasAdvance <Pottery>() && !city.HasBuilding <Granary>()) { production = new Granary(); } else if (player.HasAdvance <CeremonialBurial>() && !city.HasBuilding <Temple>()) { production = new Temple(); } else if (player.HasAdvance <Masonry>() && !city.HasBuilding <CityWalls>()) { production = new CityWalls(); } } // Create Settlers if (production == null) { if (city.Size > 3 && !city.Units.Any(x => x is Settlers) && player.Cities.Length < 10) { production = new Settlers(); } } // Create some other unit if (production == null) { if (city.Units.Length < 4) { if (player.Government is Republic || player.Government is Democratic) { if (player.HasAdvance <Writing>()) { production = new Diplomat(); } } else { if (player.HasAdvance <Automobile>()) { production = new Armor(); } else if (player.HasAdvance <Metallurgy>()) { production = new Cannon(); } else if (player.HasAdvance <Chivalry>()) { production = new Knights(); } else if (player.HasAdvance <TheWheel>()) { production = new Chariot(); } else if (player.HasAdvance <HorsebackRiding>()) { production = new Cavalry(); } else if (player.HasAdvance <IronWorking>()) { production = new Legion(); } } } else { if (player.HasAdvance <Trade>()) { production = new Caravan(); } } } // Set random production if (production == null) { IProduction[] items = city.AvailableProduction.ToArray(); production = items[Common.Random.Next(items.Length)]; } city.SetProduction(production); }
private static IUnit CreateUnit(UnitType type, int x, int y) { IUnit unit; switch (type) { case UnitType.Settlers: unit = new Settlers(); break; case UnitType.Militia: unit = new Militia(); break; case UnitType.Phalanx: unit = new Phalanx(); break; case UnitType.Legion: unit = new Legion(); break; case UnitType.Musketeers: unit = new Musketeers(); break; case UnitType.Riflemen: unit = new Riflemen(); break; case UnitType.Cavalry: unit = new Cavalry(); break; case UnitType.Knights: unit = new Knights(); break; case UnitType.Catapult: unit = new Catapult(); break; case UnitType.Cannon: unit = new Cannon(); break; case UnitType.Chariot: unit = new Chariot(); break; case UnitType.Armor: unit = new Armor(); break; case UnitType.MechInf: unit = new MechInf(); break; case UnitType.Artillery: unit = new Artillery(); break; case UnitType.Fighter: unit = new Fighter(); break; case UnitType.Bomber: unit = new Bomber(); break; case UnitType.Trireme: unit = new Trireme(); break; case UnitType.Sail: unit = new Sail(); break; case UnitType.Frigate: unit = new Frigate(); break; case UnitType.Ironclad: unit = new Ironclad(); break; case UnitType.Cruiser: unit = new Cruiser(); break; case UnitType.Battleship: unit = new Battleship(); break; case UnitType.Submarine: unit = new Submarine(); break; case UnitType.Carrier: unit = new Carrier(); break; case UnitType.Transport: unit = new Transport(); break; case UnitType.Nuclear: unit = new Nuclear(); break; case UnitType.Diplomat: unit = new Diplomat(); break; case UnitType.Caravan: unit = new Caravan(); break; default: return(null); } unit.X = x; unit.Y = y; unit.MovesLeft = unit.Move; return(unit); }
static void Main() { int numberOfLines = int.Parse(Console.ReadLine()); var legions = new Dictionary <string, Legion>(); if (numberOfLines == 0) { return; } for (int i = 0; i < numberOfLines; i++) { var input = Console.ReadLine().Split(new char[] { ' ', '=', '-', '>', ':' }, StringSplitOptions.RemoveEmptyEntries); int lastActivity = int.Parse(input[0]); string legionName = input[1]; string soldierType = input[2]; BigInteger soldierCount = BigInteger.Parse(input[3]); if (!legions.ContainsKey(legionName)) { legions[legionName] = new Legion(); var currentLegion = new Legion(); currentLegion.Activity = lastActivity; currentLegion.SoldierTypeAndCount = new Dictionary <string, BigInteger>(); currentLegion.SoldierTypeAndCount[soldierType] = soldierCount; legions[legionName] = currentLegion; } else if (!legions[legionName].SoldierTypeAndCount.ContainsKey(soldierType)) { legions[legionName].SoldierTypeAndCount[soldierType] = soldierCount; if (legions[legionName].Activity < lastActivity) { legions[legionName].Activity = lastActivity; } } else if (legions[legionName].SoldierTypeAndCount.ContainsKey(soldierType)) { legions[legionName].SoldierTypeAndCount[soldierType] += soldierCount; if (legions[legionName].Activity < lastActivity) { legions[legionName].Activity = lastActivity; } } } var command = Console.ReadLine(); int activity = 0; string soldier = string.Empty; StringBuilder printResult = new StringBuilder(); if (command.Contains("\\")) { var splitCommand = command.Split('\\'); activity = int.Parse(splitCommand[0]); soldier = splitCommand[1]; //var result = legions // .Where(a => a.Value.Activity < activity) // .OrderByDescending(c => c.Value.SoldierTypeAndCount.First().Value); var result = legions .Where(a => a.Value.Activity < activity) .Where(x => x.Value.SoldierTypeAndCount.ContainsKey(soldier)) .OrderByDescending(c => c.Value.SoldierTypeAndCount[soldier]); foreach (var item in result) { foreach (var nextItem in item.Value.SoldierTypeAndCount) { if (nextItem.Key == soldier) { printResult.AppendLine($"{item.Key} -> {nextItem.Value}"); } } } Console.Write(printResult); } else { soldier = command; foreach (var legion in legions.OrderByDescending(a => a.Value.Activity)) { if (legion.Value.SoldierTypeAndCount.ContainsKey(soldier)) { printResult.AppendLine($"{legion.Value.Activity} : {legion.Key}"); } } Console.Write(printResult); } }
private void createLegionToolStripMenuItem_Click(object sender, EventArgs e) { newLegion = new Legion(); SetupLegionEditor(newLegion); }
static void Main() { long numberOfInputs = long.Parse(Console.ReadLine()); Dictionary <string, Legion> allLegions = new Dictionary <string, Legion>(); for (long i = 0; i < numberOfInputs; i++) { var inputLine = Console.ReadLine().Split(new char[] { '=', '-', '>', ':', ' ' }, StringSplitOptions.RemoveEmptyEntries); var lastActivity = long.Parse(inputLine.First()); var legionName = inputLine.Skip(1).Take(1).First(); var soldierType = inputLine.Skip(2).Take(1).First(); var soldierCount = long.Parse(inputLine.Skip(3).First()); Dictionary <string, long> soldiers = new Dictionary <string, long>(); soldiers.Add(soldierType, soldierCount); Legion legion = new Legion() { LegionName = legionName, Activity = lastActivity, SoldierCount = soldiers, }; if (!allLegions.ContainsKey(legionName)) { allLegions.Add(legionName, legion); } else if (allLegions.ContainsKey(legionName) && !allLegions[legionName].SoldierCount.ContainsKey(soldierType)) { allLegions[legionName].SoldierCount.Add(soldierType, soldierCount); } else if (allLegions.ContainsKey(legionName) && soldiers.ContainsKey(soldierType)) { allLegions[legionName].SoldierCount[soldierType] += soldierCount; } if (lastActivity > allLegions[legionName].Activity) { allLegions[legionName].Activity = lastActivity; } } var printCommand = Console.ReadLine().Split('\\'); if (printCommand.Length > 1) { var activityMarker = long.Parse(printCommand.First()); var soldierTypeMarker = printCommand.Skip(1).First(); var output = new Dictionary <string, long>(); foreach (var legion in allLegions) { if (activityMarker > legion.Value.Activity && legion.Value.SoldierCount.ContainsKey(soldierTypeMarker)) { output.Add(legion.Key, legion.Value.SoldierCount[soldierTypeMarker]); } } var sortedOutput = from entry in output orderby entry.Value descending select entry; foreach (var item in sortedOutput) { Console.WriteLine($"{item.Key} -> {item.Value}"); } } else { var soldierTypeMarker = printCommand.First(); var output = new Dictionary <string, long>(); foreach (var legion in allLegions) { if (legion.Value.SoldierCount.ContainsKey(soldierTypeMarker)) { output.Add(legion.Key, legion.Value.Activity); } } var sortedOutput = from entry in output orderby entry.Value descending select entry; foreach (var activity in sortedOutput) { Console.WriteLine($"{activity.Value} : {activity.Key}"); } } }
static void Main(string[] args) { int inputsCount = int.Parse(Console.ReadLine()); List <Legion> legions = new List <Legion>(); string soldierType = string.Empty; for (int input = 0; input < inputsCount; input++) { string[] info = Console.ReadLine() .Split("=->: ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) .ToArray(); int lastActivity = int.Parse(info[0]); string legionName = info[1]; soldierType = info[2]; long soldiersCount = long.Parse(info[3]); var soldiers = new Dictionary <string, long>(); soldiers.Add(soldierType, soldiersCount); if (legions.All(l => l.Name != legionName)) { legions.Add(new Legion { LastActivity = lastActivity, Name = legionName, Soldiers = soldiers }); } else { Legion legion = legions.FirstOrDefault(l => l.Name == legionName); if (legion.LastActivity < lastActivity) { legion.LastActivity = lastActivity; } if (legion.Soldiers.ContainsKey(soldierType) == false) { legion.Soldiers.Add(soldierType, 0); } legion.Soldiers[soldierType] += soldiersCount; } } string[] command = Console.ReadLine() .Split("\\".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) .ToArray(); int activity = 0; soldierType = string.Empty; if (command.Length == 2) { activity = int.Parse(command[0]); soldierType = command[1]; List <Legion> tempLegions = legions.Where(l => l.LastActivity < activity && l.Soldiers.ContainsKey(soldierType)).ToList(); if (tempLegions.Count > 0) { foreach (Legion legion in tempLegions.OrderByDescending(l => l.Soldiers[soldierType])) { Console.WriteLine($"{legion.Name} -> {legion.Soldiers[soldierType]}"); } } } else { soldierType = command[0]; foreach (Legion legion in legions.Where(l => l.Soldiers.ContainsKey(soldierType)).OrderByDescending(l => l.LastActivity)) { Console.WriteLine($"{legion.LastActivity} : {legion.Name}"); } } }