Advertisement
jordan3900

Untitled

Aug 6th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _06.HornetArmada
  8. {
  9. class HornetArmada
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14. List<string> lines = new List<string>();
  15.  
  16.  
  17. for (int i = 0; i < n; i++)
  18. {
  19. string line = Console.ReadLine();
  20. lines.Add(line);
  21. }
  22. string search = Console.ReadLine();
  23. string[] tokens = search.Split('\\');
  24. if (tokens.Length>1)
  25. {
  26. long lastA = long.Parse(tokens[0]);
  27. string soldier = tokens[1];
  28. Dictionary<string, long> legionData = new Dictionary<string, long>();
  29.  
  30.  
  31. foreach (var sentence in lines)
  32. {
  33. string[] paramsOfLine = sentence.Split(new char[] { ' ', '>', '=', '-', ':' }, StringSplitOptions.RemoveEmptyEntries);
  34. long legionLastA = long.Parse(paramsOfLine[0]);
  35. if (legionLastA < lastA && sentence.Contains(soldier) )
  36. {
  37.  
  38.  
  39.  
  40. string legion = paramsOfLine[1];
  41. long countOfSold = long.Parse(paramsOfLine[3]);
  42.  
  43. if (!legionData.ContainsKey(legion))
  44. {
  45. legionData[legion] = 0;
  46. }
  47. legionData[legion] += countOfSold;
  48. }
  49. }
  50.  
  51. foreach (var some in legionData.OrderByDescending(a=>a.Value))
  52. {
  53. string leg = some.Key;
  54. long sldCount = some.Value;
  55. Console.WriteLine($"{leg} -> {sldCount}");
  56.  
  57.  
  58. }
  59.  
  60. }
  61. else
  62. {
  63. Dictionary<string, Dictionary<string, long>> lastALegionData = new Dictionary<string, Dictionary<string, long>>();
  64. string sld = tokens[0];
  65. foreach (var sentence in lines)
  66. {
  67. string[] paramsOfLine = sentence.Split(new char[] { ' ', '>', '=', '-', ':' }, StringSplitOptions.RemoveEmptyEntries);
  68. long lastA = long.Parse(paramsOfLine[0]);
  69. string legionN = paramsOfLine[1];
  70. string soldier = paramsOfLine[2];
  71. if (!lastALegionData.ContainsKey(legionN))
  72. {
  73. lastALegionData[legionN] = new Dictionary<string, long>();
  74.  
  75.  
  76. }
  77. if (!lastALegionData[legionN].ContainsKey(soldier))
  78. {
  79. lastALegionData[legionN][soldier] = 0;
  80. }
  81. if (lastALegionData[legionN][soldier]<lastA)
  82. {
  83. lastALegionData[legionN][soldier] = lastA;
  84. }
  85.  
  86. }
  87.  
  88.  
  89. foreach (var item in lastALegionData.Where(x=>x.Value.ContainsKey(sld)).OrderByDescending(a=>a.Value.Values.Max()))
  90. {
  91.  
  92. string legionN = item.Key;
  93. //if (lastALegionData[legionN].ContainsKey(sld))
  94. //{
  95. Console.WriteLine($"{item.Value.Values.Max()} : {legionN}");
  96. //}
  97.  
  98. }
  99. }
  100.  
  101.  
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement