Advertisement
Guest User

Untitled

a guest
Oct 8th, 2016
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 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 _08.Logs_Aggregator
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13.  
  14. var itemValues = new Dictionary<string, long>();
  15. itemValues.Add("fragments", 0);
  16. itemValues.Add("shards", 0);
  17. itemValues.Add("motes", 0);
  18. int count = 1;
  19.  
  20. while (count != 10)
  21. {
  22. string[] inputedInfo = Console.ReadLine().ToLower().Split().ToArray();
  23. var optainedItem = "";
  24.  
  25.  
  26. for (int i = 1; i < inputedInfo.Length; i = i + 2)
  27. {
  28. int materialValue = int.Parse(inputedInfo[i - 1]);
  29. string material = inputedInfo[i];
  30.  
  31. if (!itemValues.ContainsKey(material))
  32. {
  33. itemValues.Add(material, 0);
  34. }
  35.  
  36. itemValues[material] += materialValue;
  37.  
  38. //check if some of the legenderies is collected
  39. optainedItem = CheckForLegendery(itemValues);
  40.  
  41. if (optainedItem != "")
  42. {
  43. Console.WriteLine($"{optainedItem} obtained!");
  44. break;
  45. }
  46.  
  47. }
  48.  
  49. if (optainedItem != "")
  50. {
  51. break;
  52. }
  53. count++;
  54.  
  55. }
  56.  
  57. PrintAllItems(itemValues);
  58. }
  59.  
  60. private static void PrintAllItems(Dictionary<string, long> itemValues)
  61. {
  62. var rareItems = itemValues.Take(3).OrderByDescending(x => x.Value).ToList();
  63. var junkItems = itemValues.Skip(3).OrderBy(x => x.Key).ToList();
  64.  
  65.  
  66. foreach (var rareItem in rareItems)
  67. {
  68. Console.WriteLine($"{rareItem.Key}: {rareItem.Value}");
  69. }
  70.  
  71.  
  72. foreach (var item in junkItems)
  73. {
  74. Console.WriteLine($"{item.Key}: {item.Value}");
  75. }
  76.  
  77.  
  78. }
  79.  
  80. private static string CheckForLegendery(Dictionary<string, long> itemValues)
  81. {
  82. string itemForCraft = "";
  83. if (itemValues["fragments"] >= 250)
  84. {
  85. itemForCraft = "Valanyr";
  86. itemValues["fragments"] -= 250;
  87. }
  88.  
  89. if (itemValues["shards"] >= 250)
  90. {
  91. itemForCraft = "Shadowmourne";
  92. itemValues["shards"] -= 250;
  93. }
  94.  
  95. if (itemValues["motes"] >= 250)
  96. {
  97. itemForCraft = "Dragonwrath";
  98. itemValues["motes"] -= 250;
  99. }
  100.  
  101. return itemForCraft;
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement