Advertisement
Guest User

Untitled

a guest
Jul 9th, 2021
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace TreasureHunt
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> treasure = Console.ReadLine().Split("|").ToList();
  12.  
  13. List<string> command = Console.ReadLine().Split(" ").ToList();
  14.  
  15. while (command[0] != "Yohoho!")
  16. {
  17. if (command[0] == "Loot")
  18. {
  19. for (int i = 1; i < command.Count; i++)
  20. {
  21. if (!treasure.Contains(command[i]))
  22. {
  23. treasure.Insert(0, command[i]);
  24. }
  25. }
  26. }
  27. else if (command[0] == "Drop")
  28. {
  29. if (int.Parse(command[1]) < treasure.Count && int.Parse(command[1]) >= 0)
  30. {
  31. string element = treasure[int.Parse(command[1])];
  32. treasure.RemoveAt(int.Parse(command[1]));
  33. treasure.Add(element);
  34.  
  35. }
  36. }
  37. else if (command[0] == "Steal")
  38. {
  39. int count = int.Parse(command[1]);
  40.  
  41. if (count >= treasure.Count)
  42. {
  43. Console.WriteLine(String.Join(", ", treasure));
  44. treasure.Clear();
  45. Console.WriteLine("Failed treasure hunt.");
  46. return;
  47. }
  48. else
  49. {
  50. Console.WriteLine(String.Join(", ", treasure.GetRange(treasure.Count - count, count)));
  51. treasure.RemoveRange(treasure.Count - count, count);
  52. }
  53. }
  54.  
  55. command = Console.ReadLine().Split().ToList();
  56. }
  57.  
  58. double countElements = 0;
  59.  
  60. for (int i = 0; i < treasure.Count; i++)
  61. {
  62. countElements += treasure[i].Length;
  63. }
  64.  
  65. double averageGain = countElements / treasure.Count;
  66. Console.WriteLine($"Average treasure gain: {averageGain:f2} pirate credits.");
  67.  
  68.  
  69. }
  70. }
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement