vstoyanov

dictionary

Jan 21st, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 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 DictionaryLab
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13.  
  14. Dictionary<string, Dictionary<string, long>> allData = new Dictionary<string, Dictionary<string, long>>();
  15. Dictionary<string, Dictionary<string, long>> cacheData = new Dictionary<string, Dictionary<string, long>>();
  16.  
  17. List<string> dataSetList = new List<string>();
  18.  
  19. List<string> inputData = Console.ReadLine().Split(new char[] { ' ', '-', '>', '|' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  20.  
  21. while (inputData[0] != "thetinggoesskrra")
  22. {
  23. if (inputData.Count == 1)
  24. {
  25. string dataSet = inputData[0];
  26.  
  27. dataSetList.Add(dataSet);
  28.  
  29. if (cacheData.ContainsKey(dataSet))
  30. {
  31. foreach (var data in cacheData)
  32. {
  33. allData.Add(data.Key, data.Value);
  34. }
  35. cacheData.Remove(dataSet);
  36.  
  37. }
  38.  
  39.  
  40. }
  41. else
  42. {
  43. string dataKey = inputData[0];
  44.  
  45. long dataSize = long.Parse(inputData[1]);
  46.  
  47. string dataSet = inputData[2];
  48.  
  49. if (dataSetList.Contains(dataSet))
  50. {
  51.  
  52.  
  53. if (!allData.ContainsKey(dataSet))
  54. {
  55. allData[dataSet] = new Dictionary<string, long>();
  56. allData[dataSet][dataKey] = dataSize;
  57. }
  58. else
  59. {
  60. allData[dataSet][dataKey] = dataSize;
  61.  
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68. }
  69. else
  70. {
  71.  
  72. if (!cacheData.ContainsKey(dataSet))
  73. {
  74. cacheData[dataSet] = new Dictionary<string, long>();
  75. cacheData[dataSet][dataKey] = dataSize;
  76. }
  77. else
  78. {
  79. cacheData[dataSet][dataKey] = dataSize;
  80.  
  81. }
  82.  
  83.  
  84. }
  85.  
  86. }
  87.  
  88. inputData = Console.ReadLine().Split(new char[] { ' ', '-', '>', '|' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  89. }
  90. if (dataSetList.Count > 0)
  91. {
  92. long sum = 0;
  93.  
  94. long bestsum = long.MinValue;
  95.  
  96. string bestDataset = string.Empty;
  97.  
  98. foreach (var dataKeyEl in allData)
  99. {
  100. foreach (var dataSet in dataKeyEl.Value)
  101. {
  102. sum += dataSet.Value;
  103.  
  104. }
  105.  
  106. if (sum > bestsum)
  107. {
  108. bestsum = sum;
  109. bestDataset = dataKeyEl.Key;
  110. }
  111. sum = 0;
  112. }
  113.  
  114. Console.WriteLine($"Data Set: {bestDataset}, Total Size: {bestsum}");
  115.  
  116. foreach (var item in allData)
  117. {
  118. if (item.Key == bestDataset)
  119. {
  120. foreach (var element in item.Value)
  121. {
  122. Console.WriteLine($"$.{element.Key}");
  123. }
  124. }
  125. }
  126. }
  127.  
  128. }
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment