Advertisement
Guest User

04. Anonymous Cache

a guest
Jun 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Exam834_AnonymusCatche
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<string, Dictionary<string, long>> data = new Dictionary<string, Dictionary<string, long>>();
  12.             Dictionary<string, Dictionary<string, long>> catche = new Dictionary<string, Dictionary<string, long>>();
  13.  
  14.             string line;
  15.             string dataSet = null;
  16.             string dataKey = null;
  17.             long dataSize = 0;
  18.  
  19.             while((line = Console.ReadLine()) != "thetinggoesskrra")
  20.             {
  21.                 string[] tokens = line.Split(new[] { ' ', '-', '>', '|' }, StringSplitOptions.RemoveEmptyEntries);
  22.                    
  23.                 if(tokens.Length == 1)
  24.                 {
  25.                     dataSet = tokens[0];
  26.  
  27.                     if (!data.ContainsKey(dataSet))
  28.                     {
  29.                         data.Add(dataSet, new Dictionary<string, long>());
  30.                     }
  31.  
  32.                     if (catche.ContainsKey(dataSet))
  33.                     {
  34.                         foreach (var pair in catche[dataSet])
  35.                         {
  36.                             data[dataSet].Add(pair.Key, pair.Value);
  37.                         }
  38.                     }
  39.                 }
  40.                 else if(tokens.Length > 1)
  41.                 {
  42.                     dataKey = tokens[0];
  43.                     dataSize = long.Parse(tokens[1]);
  44.                     dataSet = tokens[2];
  45.  
  46.                     if (!data.ContainsKey(dataSet))
  47.                     {
  48.                         if (!catche.ContainsKey(dataSet))
  49.                         {
  50.                             catche.Add(dataSet, new Dictionary<string, long>());
  51.                         }
  52.                         catche[dataSet].Add(dataKey, dataSize);
  53.                     }
  54.                     else
  55.                     {
  56.                         data[dataSet].Add(dataKey, dataSize);
  57.                     }  
  58.                 }                      
  59.             }
  60.  
  61.             if (data.Count >= 1)
  62.             {
  63.                 KeyValuePair<string, Dictionary<string, long>> result = data
  64.                     .OrderByDescending(ds => ds.Value.Sum(d => d.Value))
  65.                     .First();
  66.  
  67.                 Console.WriteLine($"Data Set: {result.Key}, Total Size: {result.Value.Sum(d => d.Value)}");
  68.                 foreach (var value in result.Value)
  69.                 {
  70.                     //Just printing
  71.                     Console.WriteLine($"$.{value.Key}");
  72.                 }
  73.             }
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement