Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _04Problem_AnonumousCache
- {
- class Program
- {
- static void Main(string[] args)
- {
- var dataSets = new Dictionary<string, Dictionary<string, int>>();
- var dataCache = new Dictionary<string, Dictionary<string, int>>();
- char[] separators = { ' ', '-', '>', '|' };
- string[] inputDataInfo = Console.ReadLine().Split(separators, StringSplitOptions.RemoveEmptyEntries);
- while (inputDataInfo[0].Equals("thetinggoesskrra") == false)
- {
- if (inputDataInfo.Length == 1)
- {
- string dataSet = inputDataInfo[0];
- if (dataSets.ContainsKey(dataSet) == false)
- {
- dataSets.Add(dataSet, new Dictionary<string, int>());
- }
- if (dataCache.ContainsKey(dataSet))
- {
- dataSets[dataSet] = dataCache[dataSet];
- }
- }
- else
- {
- string dataKey = inputDataInfo[0];
- int dataSize = int.Parse(inputDataInfo[1]);
- string dataSet = inputDataInfo[2];
- if (dataSets.ContainsKey(dataSet) == false)
- {
- if (dataCache.ContainsKey(dataSet) == false)
- {
- dataCache.Add(dataSet, new Dictionary<string, int>());
- dataCache[dataSet].Add(dataKey, dataSize);
- }
- else
- {
- if (dataCache[dataSet].ContainsKey(dataKey) == false)
- {
- dataCache[dataSet].Add(dataKey, dataSize);
- }
- else
- {
- dataCache[dataSet][dataKey] += dataSize;
- }
- }
- }
- else
- {
- dataSets[dataSet].Add(dataKey, dataSize);
- }
- }
- inputDataInfo = Console.ReadLine().Split(separators, StringSplitOptions.RemoveEmptyEntries);
- }
- string currentData = string.Empty;
- string data = string.Empty;
- int currentSize = 0;
- int totalSize = 0;
- foreach (var kvp in dataSets)
- {
- foreach (var innerKvp in kvp.Value)
- {
- currentData = kvp.Key;
- currentSize += innerKvp.Value;
- }
- if (currentSize > totalSize)
- {
- data = currentData;
- totalSize = currentSize;
- }
- currentSize = 0;
- currentData = string.Empty;
- }
- Console.WriteLine($"Data Set: {data}, Total Size: {totalSize}");
- foreach (var kvp in dataSets)
- {
- foreach (var innerKvp in kvp.Value)
- {
- if (data == kvp.Key)
- {
- Console.WriteLine($"$.{innerKvp.Key}");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement