Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Problem_4___Hornet_Armada
  9. {
  10. class Program
  11. {
  12. class SingleLegionInfo
  13. {
  14. public int LastActivity { get; set; }
  15. public string LegionName { get; set; }
  16. public List<SingleSolderTypeAndCount> SoldierTypeList = new List<SingleSolderTypeAndCount>();
  17. }
  18.  
  19. class SingleSolderTypeAndCount
  20. {
  21. public string SoldierType { get; set; }
  22. public int UnitCount { get; set; }
  23. }
  24.  
  25. static void Main(string[] args)
  26. {
  27. List<SingleLegionInfo> legionInfoList = new List<SingleLegionInfo>();
  28.  
  29. int countEntries = int.Parse(Console.ReadLine());
  30. string inputLine = Console.ReadLine();
  31.  
  32. for (int i = 0; i < countEntries; i++)
  33. {
  34. string[] tokens = inputLine.Split(new char[] { ' ', '=', '-', '>', ':' }, StringSplitOptions.RemoveEmptyEntries);
  35.  
  36. int lastActivityToken = int.Parse(tokens[0]);
  37. string legionNameToken = tokens[1];
  38. string soldierTypeToken = tokens[2];
  39. int unitCountToken = int.Parse(tokens[3]);
  40.  
  41. SingleSolderTypeAndCount soldiersTypeAndUnitCount = new SingleSolderTypeAndCount();
  42.  
  43. soldiersTypeAndUnitCount.SoldierType = soldierTypeToken;
  44. soldiersTypeAndUnitCount.UnitCount = unitCountToken;
  45.  
  46. // non - existing
  47.  
  48. if (!legionInfoList.Any(x => x.LegionName == legionNameToken))
  49. {
  50. SingleLegionInfo singleLegionData = new SingleLegionInfo();
  51. singleLegionData.LastActivity = lastActivityToken;
  52. singleLegionData.LegionName = legionNameToken;
  53.  
  54. singleLegionData.SoldierTypeList = new List<SingleSolderTypeAndCount>();
  55. singleLegionData.SoldierTypeList.Add(soldiersTypeAndUnitCount);
  56.  
  57. legionInfoList.Add(singleLegionData);
  58.  
  59. inputLine = Console.ReadLine();
  60. continue;
  61. }
  62.  
  63. // existing
  64.  
  65. if (legionInfoList.Any(x => x.LegionName == legionNameToken))
  66. {
  67. SingleLegionInfo existingSingleLegionData = legionInfoList.First(x => x.LegionName == legionNameToken);
  68.  
  69. // if the lastactivity need to change conditions
  70.  
  71. if (existingSingleLegionData.LastActivity < lastActivityToken)
  72. {
  73. existingSingleLegionData.LastActivity = lastActivityToken;
  74. }
  75.  
  76.  
  77. List<SingleSolderTypeAndCount> existingSoldierTypeList = existingSingleLegionData.SoldierTypeList;
  78.  
  79. // if there is a new type of soldier rank or else
  80.  
  81. if (!existingSoldierTypeList.Any(x => x.SoldierType == soldierTypeToken))
  82. {
  83. existingSoldierTypeList.Add(soldiersTypeAndUnitCount);
  84.  
  85. inputLine = Console.ReadLine();
  86. continue;
  87. }
  88. else
  89. {
  90. // if a type of soldier already exist and we need to add unitCount to that type
  91.  
  92. if (existingSoldierTypeList.Any(x => x.SoldierType == soldierTypeToken))
  93. {
  94. SingleSolderTypeAndCount addUnits = existingSingleLegionData.SoldierTypeList.First(x => x.SoldierType == soldierTypeToken);
  95. addUnits.UnitCount = addUnits.UnitCount + unitCountToken;
  96. }
  97. }
  98.  
  99. inputLine = Console.ReadLine();
  100. continue;
  101. }
  102. }
  103.  
  104. List<SingleLegionInfo> resultList = new List<SingleLegionInfo>();
  105.  
  106. string patterOne = @"([0-9]+\\[A-Za-z])\w+";
  107. Regex patterOptionOne = new Regex(patterOne);
  108.  
  109. bool containsValidMatchForFirst = patterOptionOne.IsMatch(inputLine);
  110.  
  111. if (containsValidMatchForFirst)
  112. {
  113. //Console.WriteLine(inputLine + " : First Type Input");
  114.  
  115. string[] getInputeDate = inputLine.Split(new char[] { ' ', '\\' }, StringSplitOptions.RemoveEmptyEntries);
  116. int findLastActivity = int.Parse(getInputeDate[0]);
  117. string findType = getInputeDate[1];
  118.  
  119. foreach (SingleLegionInfo item in legionInfoList)
  120. {
  121. if (item.LastActivity != findLastActivity && item.SoldierTypeList.Any(x => (x.SoldierType == findType)))
  122. {
  123. SingleLegionInfo itemToList = item;
  124. resultList.Add(itemToList);
  125. }
  126. }
  127.  
  128. // нека първо подредим по големина на армията
  129.  
  130. // място за код
  131. //
  132.  
  133. foreach (SingleLegionInfo item in resultList) //
  134. {
  135. SingleSolderTypeAndCount element = item.SoldierTypeList.First(x => x.SoldierType == findType);
  136. int result = element.UnitCount;
  137. Console.WriteLine($"{item.LegionName} -> {result}");
  138. }
  139.  
  140. }
  141. else
  142. {
  143. // това няма нужда за сега
  144. Console.WriteLine(inputLine + " : Second Type Input");
  145.  
  146. }
  147.  
  148.  
  149.  
  150. }
  151.  
  152.  
  153. }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement