Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Nested_Dictionaries
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Input/Main/Start
- string input = Console.ReadLine();
- //Dictionary for holding the info shit
- var _DataSets = new List<string>();
- var _DataDict = new Dictionary<string, Dictionary<string, long>>();
- //Main cycle, untill input gets command to stop
- while (input != "thetinggoesskrra")
- {
- //Split the input to commands
- var commands = input.Split(" ->|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToArray();
- //If input is only { DataSet }
- if (commands.Length == 1)
- {
- string DataSet = commands[0];
- _DataSets.Add(DataSet);
- }
- else //Enter all the info
- {
- //{dataKey} -> {dataSize} | {dataSet}
- string DataKey = commands[0];
- long DataSize = long.Parse(commands[1]);
- string DataSet = commands[2];
- //Create dataset if it doesnt exist
- if (!_DataDict.ContainsKey(DataSet))
- {
- _DataDict[DataSet] = new Dictionary<string, long>();
- }
- // ^ add the info to the data set
- _DataDict[DataSet][DataKey] = DataSize;
- }
- //Repeat input
- input = Console.ReadLine();
- }
- //Delete the DataSets which do not exist in both cache and dict
- foreach (var item in _DataSets)
- {
- if (!_DataDict.ContainsKey(item))
- {
- _DataDict.Remove(item);
- }
- }
- //Check if there are any data sets
- if (_DataSets.Count > 0)
- {
- //Output
- var result = _DataDict.OrderByDescending(x => x.Value.Sum(e => e.Value)).First();
- // result.first key we go in the result value = dict(secondary keys) and then SUM their VALS
- Console.WriteLine($"Data Set: {result.Key}, Total Size: {result.Value.Sum(e => e.Value)}");
- foreach (var item in result.Value)
- {
- Console.WriteLine($"$.{item.Key}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement