Advertisement
bullit3189

Legendary Farming - Dictionaries

Jan 15th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Program
  6. {
  7. public static void Main()
  8. {
  9. Dictionary<string, int> keyMaterials = new Dictionary<string, int>();
  10. SortedDictionary<string, int> junkMaterials = new SortedDictionary<string, int>();
  11.  
  12. keyMaterials.Add("shards", 0);
  13. keyMaterials.Add("fragments", 0);
  14. keyMaterials.Add("motes", 0);
  15.  
  16. while (true)
  17. {
  18. string[] input = Console.ReadLine().Split();
  19. bool hasToBreak = false;
  20.  
  21. for (int i=0; i<input.Length; i+=2)
  22. {
  23. int quantity = int.Parse(input[i]);
  24. string material = input[i+1].ToLower();
  25.  
  26. if (material == "fragments" || material == "shards" || material == "motes")
  27. {
  28. keyMaterials[material]+=quantity;
  29.  
  30. if (keyMaterials[material]>=250)
  31. {
  32. keyMaterials[material]-=250;
  33.  
  34. if (material == "fragments")
  35. {
  36. Console.WriteLine("Valanyr obtained!");
  37. hasToBreak=true;
  38. break;
  39. }
  40. else if (material == "shards")
  41. {
  42. Console.WriteLine("Shadowmourne obtained!");
  43. hasToBreak=true;
  44. break;
  45. }
  46. else
  47. {
  48. Console.WriteLine("Dragonwrath obtained!");
  49. hasToBreak=true;
  50. break;
  51. }
  52.  
  53. }
  54.  
  55. }
  56. else
  57. {
  58. if (!junkMaterials.ContainsKey(material))
  59. {
  60. junkMaterials[material]=0;
  61. }
  62. junkMaterials[material]+=quantity;
  63. }
  64. }
  65. if (hasToBreak)
  66. {
  67. break;
  68. }
  69.  
  70. }
  71. foreach (var kvp in keyMaterials.OrderByDescending(kvp => kvp.Value).ThenBy(kvp => kvp.Key))
  72. {
  73. Console.WriteLine("{0}: {1}",kvp.Key,kvp.Value);
  74. }
  75. foreach (var kvp in junkMaterials)
  76. {
  77. Console.WriteLine("{0}: {1}",kvp.Key,kvp.Value);
  78. }
  79.  
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement