Advertisement
miroLLL

04Problem-AnonumousCache

Feb 19th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04Problem_AnonumousCache
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var dataSets = new Dictionary<string, Dictionary<string, int>>();
  12.             var dataCache = new Dictionary<string, Dictionary<string, int>>();
  13.  
  14.             char[] separators = { ' ', '-', '>', '|' };
  15.  
  16.             string[] inputDataInfo = Console.ReadLine().Split(separators, StringSplitOptions.RemoveEmptyEntries);
  17.  
  18.             while (inputDataInfo[0].Equals("thetinggoesskrra") == false)
  19.             {
  20.                 if (inputDataInfo.Length == 1)
  21.                 {
  22.                     string dataSet = inputDataInfo[0];
  23.  
  24.                     if (dataSets.ContainsKey(dataSet) == false)
  25.                     {
  26.                         dataSets.Add(dataSet, new Dictionary<string, int>());
  27.                     }
  28.  
  29.                     if (dataCache.ContainsKey(dataSet))
  30.                     {
  31.                         dataSets[dataSet] = dataCache[dataSet];
  32.                     }
  33.  
  34.                 }
  35.                 else
  36.                 {
  37.                     string dataKey = inputDataInfo[0];
  38.                     int dataSize = int.Parse(inputDataInfo[1]);
  39.                     string dataSet = inputDataInfo[2];
  40.  
  41.                     if (dataSets.ContainsKey(dataSet) == false)
  42.                     {
  43.                         if (dataCache.ContainsKey(dataSet) == false)
  44.                         {
  45.                             dataCache.Add(dataSet, new Dictionary<string, int>());
  46.                             dataCache[dataSet].Add(dataKey, dataSize);
  47.                         }
  48.                         else
  49.                         {
  50.                             if (dataCache[dataSet].ContainsKey(dataKey) == false)
  51.                             {
  52.                                 dataCache[dataSet].Add(dataKey, dataSize);
  53.                             }
  54.                             else
  55.                             {
  56.                                 dataCache[dataSet][dataKey] += dataSize;
  57.                             }
  58.                         }
  59.  
  60.                     }
  61.                     else
  62.                     {
  63.                         dataSets[dataSet].Add(dataKey, dataSize);
  64.                     }
  65.                 }
  66.  
  67.                 inputDataInfo = Console.ReadLine().Split(separators, StringSplitOptions.RemoveEmptyEntries);
  68.             }
  69.  
  70.             string currentData = string.Empty;
  71.             string data = string.Empty;
  72.  
  73.             int currentSize = 0;
  74.             int totalSize = 0;
  75.  
  76.             foreach (var kvp in dataSets)
  77.             {
  78.                 foreach (var innerKvp in kvp.Value)
  79.                 {
  80.                     currentData = kvp.Key;
  81.                     currentSize += innerKvp.Value;
  82.                 }
  83.  
  84.                 if (currentSize > totalSize)
  85.                 {
  86.                     data = currentData;
  87.                     totalSize = currentSize;
  88.                 }
  89.                 currentSize = 0;
  90.                 currentData = string.Empty;
  91.             }
  92.  
  93.             Console.WriteLine($"Data Set: {data}, Total Size: {totalSize}");
  94.  
  95.             foreach (var kvp in dataSets)
  96.             {
  97.                 foreach (var innerKvp in kvp.Value)
  98.                 {
  99.                     if (data == kvp.Key)
  100.                     {
  101.                         Console.WriteLine($"$.{innerKvp.Key}");
  102.                     }
  103.                 }
  104.             }
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement