Advertisement
Guest User

Untitled

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