Advertisement
Zarodath

Untitled

Dec 9th, 2017
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Nested_Dictionaries
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. //Input/Main/Start
  14. string input = Console.ReadLine();
  15.  
  16. //Dictionary for holding the info shit
  17. var _DataSets = new List<string>();
  18. var _DataDict = new Dictionary<string, Dictionary<string, long>>();
  19.  
  20.  
  21. //Main cycle, untill input gets command to stop
  22. while (input != "thetinggoesskrra")
  23. {
  24. //Split the input to commands
  25. var commands = input.Split(" ->|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToArray();
  26.  
  27. //If input is only { DataSet }
  28. if (commands.Length == 1)
  29. {
  30. string DataSet = commands[0];
  31. _DataSets.Add(DataSet);
  32. }
  33. else //Enter all the info
  34. {
  35. //{dataKey} -> {dataSize} | {dataSet}
  36. string DataKey = commands[0];
  37. long DataSize = long.Parse(commands[1]);
  38. string DataSet = commands[2];
  39.  
  40. //Create dataset if it doesnt exist
  41. if (!_DataDict.ContainsKey(DataSet))
  42. {
  43. _DataDict[DataSet] = new Dictionary<string, long>();
  44. }
  45. // ^ add the info to the data set
  46. _DataDict[DataSet][DataKey] = DataSize;
  47. }
  48. //Repeat input
  49. input = Console.ReadLine();
  50. }
  51.  
  52.  
  53.  
  54. //Delete the DataSets which do not exist in both cache and dict
  55. foreach (var item in _DataSets)
  56. {
  57. if (!_DataDict.ContainsKey(item))
  58. {
  59. _DataDict.Remove(item);
  60. }
  61. }
  62. //Check if there are any data sets
  63. if (_DataSets.Count > 0)
  64. {
  65. //Output
  66. var result = _DataDict.OrderByDescending(x => x.Value.Sum(e => e.Value)).First();
  67. // result.first key we go in the result value = dict(secondary keys) and then SUM their VALS
  68. Console.WriteLine($"Data Set: {result.Key}, Total Size: {result.Value.Sum(e => e.Value)}");
  69. foreach (var item in result.Value)
  70. {
  71. Console.WriteLine($"$.{item.Key}");
  72. }
  73. }
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement