Advertisement
Guest User

Untitled

a guest
Feb 27th, 2021
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Treasure_Hunt
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> treasure = Console.ReadLine()
  12. .Split("|", StringSplitOptions.RemoveEmptyEntries)
  13. .ToList();
  14. List<string> steal = new List<string>();
  15.  
  16. while (true)
  17. {
  18. string command = Console.ReadLine();
  19. if (command == "Yohoho!")
  20. {
  21. break;
  22. }
  23.  
  24. string[] token = command.Split();
  25. string word = token[0];
  26.  
  27. if (word == "Loot")
  28. {
  29. for (int i = 1; i < token.Length; i++)
  30. {
  31. if (!treasure.Contains(token[i]))
  32. {
  33. treasure.Insert(0, token[i]);
  34. }
  35. }
  36. }
  37.  
  38. else if (word == "Drop")
  39. {
  40. int index = int.Parse(token[1]);
  41. if (index >= 0 && index < treasure.Count)
  42. {
  43. string removedItem = treasure[index];
  44. treasure.RemoveAt(index);
  45. treasure.Add(removedItem);
  46. }
  47.  
  48. }
  49.  
  50. else if (word == "Steal")
  51. {
  52. int count = int.Parse(token[1]);
  53.  
  54. if (count <= treasure.Count)
  55. {
  56. for (int i = treasure.Count - count; i < treasure.Count; i++)
  57. {
  58. steal.Add(treasure[i]);
  59. }
  60. Console.WriteLine(string.Join(", ", steal));
  61.  
  62. treasure.RemoveRange(treasure.Count - count, count);
  63. }
  64.  
  65. else
  66. {
  67. for (int i = 0; i < treasure.Count; i++)
  68. {
  69. steal.Add(treasure[i]);
  70. }
  71. Console.WriteLine(string.Join(", ", steal));
  72.  
  73. treasure.RemoveRange(0, treasure.Count);
  74. }
  75.  
  76. }
  77.  
  78. }
  79.  
  80. double sum = 0;
  81. double avg = 0;
  82.  
  83. foreach (var item in treasure)
  84. {
  85. sum = sum + item.Length;
  86. }
  87.  
  88. avg = sum / treasure.Count;
  89.  
  90. if (treasure.Count != 0)
  91. {
  92. Console.WriteLine($"Average treasure gain: {avg:f2} pirate credits.");
  93. }
  94.  
  95. else
  96. {
  97. Console.WriteLine("Failed treasure hunt.");
  98. }
  99.  
  100. }
  101. }
  102. }
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement