Advertisement
AnastasiyaG

Untitled

Feb 28th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Treasure_Hunt
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10.  
  11. List<string> treasureLIst = Console.ReadLine()
  12. .Split('|', StringSplitOptions.RemoveEmptyEntries)
  13. .ToList();
  14. while (true)
  15. {
  16. string[] commands = Console.ReadLine()
  17. .Split()
  18. .ToArray();
  19. if (commands[0] == "Yohoho!")
  20. { break; }
  21. switch (commands[0])
  22. {
  23. case "Loot":
  24.  
  25. treasureLIst = GetLootedList(treasureLIst, commands);
  26. break;
  27. case "Drop":
  28.  
  29. int index = int.Parse(commands[1]);
  30. if (index < 0 || index > treasureLIst.Count - 1)
  31. { continue; }
  32. else
  33. {
  34. string current = treasureLIst[index];
  35. treasureLIst.RemoveAt(index);
  36. treasureLIst.Add(current);
  37. }
  38. break;
  39. case "Steal":
  40. int count = int.Parse(commands[1]);
  41. if (count <= 0)
  42. { continue; }
  43. GetStealList(treasureLIst, count);
  44. break;
  45.  
  46. }
  47.  
  48.  
  49. }
  50. double sumofletters = 0;
  51. for (int i = 0; i < treasureLIst.Count; i++)
  52. {
  53. int cur = treasureLIst[i].Length;
  54. sumofletters += cur;
  55.  
  56.  
  57. }
  58.  
  59.  
  60.  
  61. if (treasureLIst.Count > 0)
  62. {
  63. double needForPrint = sumofletters / (treasureLIst.Count);
  64. Console.WriteLine($"Average treasure gain: {needForPrint:f2} pirate credits.");
  65. }
  66. else
  67. { Console.WriteLine("Failed treasure hunt."); }
  68.  
  69.  
  70. }
  71.  
  72. static List<string> GetStealList(List<string> treasureLIst, int count)
  73. {
  74. List<string> stealitems = new List<string>();
  75. for (int i = 1; i <= count; i++)
  76. {
  77. string current = treasureLIst[treasureLIst.Count - 1];
  78. stealitems.Add(current);
  79. treasureLIst.RemoveAt(treasureLIst.Count - 1);
  80.  
  81. }
  82. stealitems.Reverse();
  83. Console.WriteLine(String.Join(", ", stealitems));
  84. return treasureLIst;
  85. }
  86.  
  87. static List<string> GetLootedList(List<string> treasureLIst, string[] commands)
  88. {
  89. List<string> newitems = new List<string>();
  90. List<string> newTresure = new List<string>();
  91.  
  92. for (int i = 1; i < commands.Length; i++)
  93. {
  94. newitems.Add(commands[i]);
  95. if (treasureLIst.Contains(commands[i]))
  96. {
  97. newitems.Remove(commands[i]);
  98. }
  99. }
  100. newitems.Reverse();
  101. for (int j = 0; j < newitems.Count; j++)
  102. {
  103. newTresure.Add(newitems[j]);
  104.  
  105. }
  106. for (int k = 0; k < treasureLIst.Count; k++)
  107. {
  108. newTresure.Add(treasureLIst[k]);
  109.  
  110. }
  111. treasureLIst = newTresure;
  112. return treasureLIst;
  113. }
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement