Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Problem_4___Hornet_Armada
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- class Program
- {
- class SingleLegionInfo
- {
- public int LastActivity { get; set; }
- public string LegionName { get; set; }
- public List<SingleSolderTypeAndCount> SoldierTypeList =
- new List<SingleSolderTypeAndCount>();
- }
- class SingleSolderTypeAndCount
- {
- public string SoldierType { get; set; }
- public /*int*/long UnitCount { get; set; }
- }
- static void Main(string[] args)
- {
- List<SingleLegionInfo> legionInfoList = new List<SingleLegionInfo>();
- int countEntries = int.Parse(Console.ReadLine());
- for (int i = 0; i < countEntries; i++)
- {
- string inputLine = Console.ReadLine();
- string[] tokens = inputLine.Split(
- new/*char*/string[] { " ", "=", "->", ":" },
- StringSplitOptions.RemoveEmptyEntries);
- int lastActivityToken = int.Parse(tokens[0]);
- string legionNameToken = tokens[1];
- string soldierTypeToken = tokens[2];
- long unitCountToken = long.Parse(tokens[3]);
- // пъво проверряваш дали не са създадени вече:
- //SingleSolderTypeAndCount soldiersTypeAndUnitCount = new SingleSolderTypeAndCount();
- //soldiersTypeAndUnitCount.SoldierType = soldierTypeToken;
- //soldiersTypeAndUnitCount.UnitCount = unitCountToken;
- // non - existing
- if (!legionInfoList.Any(x => x.LegionName == legionNameToken))
- {
- // ако няма такъв легион го създаваш и добавяш:
- SingleLegionInfo singleLegionData = new SingleLegionInfo();
- singleLegionData.LastActivity = lastActivityToken;
- singleLegionData.LegionName = legionNameToken;
- legionInfoList.Add(singleLegionData);
- // като създадеш легион тои си създава сам нов списък:
- // ако горе махнеш новия лист може да си го задаваш от тук:
- //singleLegionData.SoldierTypeList = new List<SingleSolderTypeAndCount>();
- //това го правиш накрая на проверките и изобщо в цикъла
- //inputLine = Console.ReadLine();
- //continue;
- }
- // existing
- SingleLegionInfo existingSingleLegionData =
- legionInfoList.Where(x => x.LegionName == legionNameToken).First();
- // if the lastactivity need to change conditions
- if (existingSingleLegionData.LastActivity < lastActivityToken)
- {
- existingSingleLegionData.LastActivity = lastActivityToken;
- }
- //List<SingleSolderTypeAndCount>existingSoldierTypeList=existingSingleLegionData.SoldierTypeLst;
- // if there is a new type of soldier rank or else
- if (!existingSingleLegionData.SoldierTypeList.Any(x => x.SoldierType == soldierTypeToken))
- {
- SingleSolderTypeAndCount newSoldiers = new SingleSolderTypeAndCount();
- newSoldiers.SoldierType = soldierTypeToken;
- newSoldiers.UnitCount = unitCountToken;
- existingSingleLegionData.SoldierTypeList.Add(newSoldiers);
- //existingSoldierTypeList.Add(soldiersTypeAndUnitCount);
- //inputLine = Console.ReadLine();
- //continue;
- }
- else
- {
- SingleSolderTypeAndCount existingSoldiers =
- existingSingleLegionData.SoldierTypeList
- .Where(x => x.SoldierType == soldierTypeToken).First();
- existingSoldiers.UnitCount += unitCountToken;
- // if a type of soldier already exist and we need to add unitCount to that type
- //if (existingSoldierTypeList.Any(x => x.SoldierType == soldierTypeToken))
- //{
- // SingleSolderTypeAndCount addUnits =existingSingleLegionData.SoldierTypeList.Firs(x= x.SoldierType ==soldierTypeToken);
- // addUnits.UnitCount = addUnits.UnitCount + unitCountToken;
- //}
- }
- //inputLine = Console.ReadLine();
- //continue;
- }
- string[] lastRequest = Console.ReadLine()
- .Split(new[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
- //List<SingleLegionInfo> resultList = new List<SingleLegionInfo>();
- //string patterOne = @"([0-9]+\\[A-Za-z])\w+";
- //Regex patterOptionOne = new Regex(patterOne);
- //bool containsValidMatchForFirst = patterOptionOne.IsMatch(inputLine);
- if (lastRequest.Length == 2)
- {
- int activity = int.Parse(lastRequest[0]);
- string soldierType = lastRequest[1];
- var output = legionInfoList.Where(x => x.LastActivity < activity)
- .ToDictionary(
- x => x.LegionName,
- x => x.SoldierTypeList.Where(y => y.SoldierType == soldierType)
- .ToDictionary(y => y.SoldierType, y => y.UnitCount))
- .OrderByDescending(c => c.Value.Values.FirstOrDefault());
- foreach (var legion in output)
- {
- foreach (var sCount in legion.Value)
- {
- Console.WriteLine($"{legion.Key} -> {sCount.Value}");
- }
- }
- //Console.WriteLine(inputLine + " : First Type Input");
- //string[] getInputeDate = inputLine.Split(new char[] { ' ', '\\' }, StringSplitOptions.RemoveEmptyEntries);
- //int findLastActivity = int.Parse(getInputeDate[0]);
- //string findType = getInputeDate[1];
- //foreach (SingleLegionInfo item in legionInfoList)
- //{
- // if (item.LastActivity != findLastActivity && item.SoldierTypeList.Any(x => (x.SoldierType == findType)))
- // {
- // SingleLegionInfo itemToList = item;
- // resultList.Add(itemToList);
- // }
- //}
- //// нека първо подредим по големина на армията
- //// място за код
- ////
- //foreach (SingleLegionInfo item in resultList) //
- //{
- // SingleSolderTypeAndCount element = item.SoldierTypeList.First(x => x.SoldierType == findType);
- // int result = element.UnitCount;
- // Console.WriteLine($"{item.LegionName} -> {result}");
- //}
- }
- if(lastRequest.Length == 1)
- {
- string soldierType = lastRequest[0];
- foreach (var item in legionInfoList.OrderByDescending(x => x.LastActivity))
- {
- if (item.SoldierTypeList.Any(x => x.SoldierType == soldierType))
- {
- Console.WriteLine($"{item.LastActivity} : {item.LegionName}");
- }
- }
- // това няма нужда за сега
- //Console.WriteLine(inputLine + " : Second Type Input");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement