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.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace Problem_4___Hornet_Armada
- {
- 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 UnitCount { get; set; }
- }
- static void Main(string[] args)
- {
- List<SingleLegionInfo> legionInfoList = new List<SingleLegionInfo>();
- int countEntries = int.Parse(Console.ReadLine());
- string inputLine = Console.ReadLine();
- for (int i = 0; i < countEntries; i++)
- {
- string[] tokens = inputLine.Split(new char[] { ' ', '=', '-', '>', ':' }, StringSplitOptions.RemoveEmptyEntries);
- int lastActivityToken = int.Parse(tokens[0]);
- string legionNameToken = tokens[1];
- string soldierTypeToken = tokens[2];
- int unitCountToken = int.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;
- singleLegionData.SoldierTypeList = new List<SingleSolderTypeAndCount>();
- singleLegionData.SoldierTypeList.Add(soldiersTypeAndUnitCount);
- legionInfoList.Add(singleLegionData);
- inputLine = Console.ReadLine();
- continue;
- }
- // existing
- if (legionInfoList.Any(x => x.LegionName == legionNameToken))
- {
- SingleLegionInfo existingSingleLegionData = legionInfoList.First(x => x.LegionName == legionNameToken);
- // if the lastactivity need to change conditions
- if (existingSingleLegionData.LastActivity < lastActivityToken)
- {
- existingSingleLegionData.LastActivity = lastActivityToken;
- }
- List<SingleSolderTypeAndCount> existingSoldierTypeList = existingSingleLegionData.SoldierTypeList;
- // if there is a new type of soldier rank or else
- if (!existingSoldierTypeList.Any(x => x.SoldierType == soldierTypeToken))
- {
- existingSoldierTypeList.Add(soldiersTypeAndUnitCount);
- inputLine = Console.ReadLine();
- continue;
- }
- else
- {
- // 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.First(x => x.SoldierType == soldierTypeToken);
- addUnits.UnitCount = addUnits.UnitCount + unitCountToken;
- }
- }
- inputLine = Console.ReadLine();
- continue;
- }
- }
- 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 (containsValidMatchForFirst)
- {
- //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}");
- }
- }
- else
- {
- // това няма нужда за сега
- Console.WriteLine(inputLine + " : Second Type Input");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement