Teo_Yanchev

Dictionaries - 03. LegendaryFarming - C# Fundamentals

Oct 4th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5.  
  6. namespace _2._Common_Elements
  7. {
  8. class Program
  9. {
  10. static void Main()
  11. {
  12. Dictionary<string, int> materials = new Dictionary<string, int>();
  13. Dictionary<string, int> junks = new Dictionary<string, int>();
  14.  
  15. materials["shards"] = 0;
  16. materials["fragments"] = 0;
  17. materials["motes"] = 0;
  18. bool isObtained = true;
  19.  
  20. while (isObtained)
  21. {
  22. string[] givenMaterials = Console.ReadLine()
  23. .ToLower()
  24. .Split()
  25. .ToArray();
  26.  
  27. for (int i = 0; i < givenMaterials.Length; i +=2)
  28. {
  29. int currentQuantity = int.Parse(givenMaterials[i]);
  30. string currentMaterial = givenMaterials[i + 1];
  31.  
  32. if (currentMaterial == "shards")
  33. {
  34. materials[currentMaterial] += currentQuantity;
  35. if (materials[currentMaterial] >= 250)
  36. {
  37. Console.WriteLine("Shadowmourne obtained!");
  38. materials[currentMaterial] -= 250;
  39. isObtained = false;
  40. break;
  41. }
  42. }
  43. else if (currentMaterial == "fragments")
  44. {
  45. materials[currentMaterial] += currentQuantity;
  46. if (materials[currentMaterial] >= 250)
  47. {
  48. Console.WriteLine("Valanyr obtained!");
  49. materials[currentMaterial] -= 250;
  50. isObtained = false;
  51. break;
  52. }
  53. }
  54. else if (currentMaterial == "motes")
  55. {
  56. materials[currentMaterial] += currentQuantity;
  57. if (materials[currentMaterial] >= 250)
  58. {
  59. Console.WriteLine("Dragonwrath obtained!");
  60. materials[currentMaterial] -= 250;
  61. isObtained = false;
  62. break;
  63. }
  64. }
  65. else
  66. {
  67. if (!junks.ContainsKey(currentMaterial))
  68. {
  69. junks[currentMaterial] = 0;
  70. }
  71.  
  72. junks[currentMaterial] += currentQuantity;
  73. }
  74.  
  75. }
  76. }
  77. materials = materials
  78. .OrderByDescending(x => x.Value)
  79. .ThenBy(x => x.Key)
  80. .ToDictionary(x => x.Key, x => x.Value);
  81.  
  82. junks = junks
  83. .OrderBy(x => x.Key)
  84. .ToDictionary(x => x.Key, x => x.Value);
  85.  
  86. foreach (var kvp in materials)
  87. {
  88. Console.WriteLine($"{kvp.Key}: {kvp.Value}");
  89. }
  90.  
  91. foreach (var kvp in junks)
  92. {
  93. Console.WriteLine($"{kvp.Key}: {kvp.Value}");
  94. }
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment