Advertisement
Guest User

Untitled

a guest
Dec 7th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace p_04
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var data = new Dictionary<string, Dictionary<string, decimal>>();
  12.             var cache = new Dictionary<string, Dictionary<string, decimal>>();
  13.             List<string> listOfDataSets = new List<string>();
  14.  
  15.             while (true)
  16.             {
  17.                 string[] commands = Console.ReadLine()
  18.                     .Split(new char[] { ' ', '-', '>', '|' }, StringSplitOptions.RemoveEmptyEntries);
  19.  
  20.                 if (commands[0] == "thetinggoesskrra")
  21.                 {
  22.                     decimal first = 0.0m;
  23.                     decimal second = 0.0m;
  24.                     for (int i = 0; i < listOfDataSets.Count; i++)
  25.                     {
  26.                         if (cache.ContainsKey(listOfDataSets[i]))
  27.                         {
  28.                             first = cache.Values.SelectMany(dict => dict.Values.ToList()).Sum();
  29.                         }
  30.                         if (data.ContainsKey(listOfDataSets[i]))
  31.                         {
  32.                             second = data.Values.SelectMany(dict => dict.Values.ToList()).Sum();
  33.                         }
  34.                     }
  35.  
  36.                     var result = new Dictionary<string, Dictionary<string, decimal>>();
  37.                     if (first > second)
  38.                     {
  39.                         result = cache;
  40.                     }
  41.                     else
  42.                     {
  43.                         result = data;
  44.                     }
  45.  
  46.                     foreach (var kvp in result.OrderByDescending(a => a.Value.Values.Sum()))
  47.                     {
  48.                         Console.WriteLine($"Data Set: {kvp.Key}, Total Size: {kvp.Value.Values.Sum()}");
  49.                         foreach (var dataKeys in kvp.Value)
  50.                         {
  51.                             Console.WriteLine($"$.{string.Join("", dataKeys.Key)}");
  52.                         }
  53.                         return;
  54.                     }
  55.                 }
  56.  
  57.                 if (commands.Length == 1)
  58.                 {
  59.                     listOfDataSets.Add(commands[0]);
  60.                     continue;
  61.                 }
  62.  
  63.                 string dataKey = commands[0];
  64.                 decimal dataSize = decimal.Parse(commands[1]);
  65.                 string dataSet = commands[2];
  66.  
  67.                 if (listOfDataSets.Contains(dataSet)) // if currentDataSet is contain in listOfDataSets
  68.                 {
  69.                     if (data.ContainsKey(dataSet) == false) // if currentDataSet is NOT contain in data
  70.                     {
  71.                         data.Add(dataSet, new Dictionary<string, decimal>());
  72.                     }
  73.                     data[dataSet].Add(dataKey, dataSize);
  74.                 }
  75.                 else // if currentDataSet is NOT contain in listOfDataSets
  76.                 {
  77.                     if (cache.ContainsKey(dataSet) == false) // if currentDataSet is NOT contains in cache
  78.                     {
  79.                         cache.Add(dataSet, new Dictionary<string, decimal>());
  80.                     }
  81.                     cache[dataSet].Add(dataKey, dataSize);
  82.                 }
  83.             }
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement