Advertisement
pavsavov

4.AnonymousCache

Nov 5th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 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. using System.Numerics;
  7.  
  8. namespace _3.TaskThree
  9. {
  10. class TaskThree
  11. {
  12. static void Main(string[] args)
  13. {
  14. Dictionary<string, Dictionary<string, BigInteger>> dataSetsDictionary = new Dictionary<string, Dictionary<string, BigInteger>>();
  15. while (true)
  16. {
  17. string[] input = Console.ReadLine()
  18. .Split(new string[] { " -> ", " | " }
  19. , StringSplitOptions.RemoveEmptyEntries);
  20. if (input[0] == "thetinggoesskrra")
  21. {
  22. break;
  23. }
  24. else if (input.Length < 3)
  25. {
  26. continue;
  27. }
  28. else
  29. {
  30.  
  31. if (input.Length != 1 && input.Length != 0)
  32. {
  33. string dataKey = input[0];
  34. BigInteger dataSize = BigInteger.Parse(input[1]);
  35. string dataSet = input[2];
  36.  
  37. if (!dataSetsDictionary.ContainsKey(dataSet))
  38. {
  39. dataSetsDictionary.Add(dataSet, new Dictionary<string, BigInteger>());
  40. dataSetsDictionary[dataSet].Add(dataKey, dataSize);
  41. }
  42. else if (dataSetsDictionary.ContainsKey(dataSet))
  43. {
  44. dataSetsDictionary[dataSet].Add(dataKey, dataSize);
  45. }
  46. }
  47. else
  48. {
  49. continue;
  50. }
  51. }
  52. }
  53. //PrinTing:
  54. var dataSetAndDataSize = new Dictionary<string, BigInteger>();
  55. foreach (var token in dataSetsDictionary)
  56. {
  57. foreach (var items in token.Value)
  58. {
  59. if (!dataSetAndDataSize.ContainsKey(token.Key))
  60. {
  61. dataSetAndDataSize.Add(token.Key, items.Value);
  62.  
  63. }
  64. else if (dataSetAndDataSize.ContainsKey(token.Key))
  65. {
  66. dataSetAndDataSize[token.Key] += items.Value;
  67. }
  68. }
  69. }
  70.  
  71. var biggestDataSize = dataSetAndDataSize.OrderByDescending(z => z.Value).ToDictionary(pair => pair.Key, pair => pair.Value);
  72. Console.WriteLine(@"Data Set: {0}, Total Size: {1}", biggestDataSize.Keys.First(), biggestDataSize.Values.First());
  73.  
  74. foreach (var items in dataSetsDictionary)
  75. {
  76. foreach (var tokens in items.Value)
  77. {
  78. if (items.Key == biggestDataSize.Keys.First())
  79. {
  80. Console.WriteLine(@"$.{0}", tokens.Key);
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement