Advertisement
TheaThea

Untitled

Feb 26th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _15.RabbitHole
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<string> obstacles = Console.ReadLine().Split().ToList();
  14. var energy = int.Parse(Console.ReadLine());
  15.  
  16. var currentIndex = 0;
  17.  
  18. while (energy > 0)
  19. {
  20. var field = obstacles[currentIndex];
  21. var command = field.Split('|')[0];
  22.  
  23.  
  24. switch (command)
  25. {
  26. case "Left":
  27. var jump = int.Parse(field.Split('|')[1]);
  28. if (currentIndex - jump >= 0)
  29. {
  30. currentIndex -= jump;
  31.  
  32. }
  33.  
  34. else
  35. {
  36. var steps = Math.Abs(currentIndex - jump);
  37. currentIndex = steps % obstacles.Count;
  38. }
  39. energy -= jump;
  40. break;
  41.  
  42. case "Right":
  43. jump = int.Parse(field.Split('|')[1]);
  44. currentIndex = (currentIndex + jump) % obstacles.Count;
  45. energy -= jump;
  46. break;
  47.  
  48. case "Bomb":
  49. jump = int.Parse(field.Split('|')[1]);
  50. obstacles.RemoveAt(currentIndex);
  51. currentIndex = 0;
  52. energy -= jump;
  53.  
  54. if (energy <= 0)
  55. {
  56. Console.WriteLine("You are dead due to bomb explosion!");
  57. return;
  58. }
  59.  
  60. break;
  61.  
  62. case "RabbitHole":
  63. Console.WriteLine("You have 5 years to save Kennedy!");
  64. return;
  65. }
  66. if (obstacles[obstacles.Count - 1] != "RabbitHole")
  67. {
  68. obstacles.RemoveAt(obstacles.Count - 1);
  69. obstacles.Add($"Bomb|{energy}");
  70. }
  71. else
  72. {
  73. obstacles.Add($"Bomb|{energy}");
  74. }
  75.  
  76. }
  77.  
  78. Console.WriteLine("You are tired. You can't continue the mission.");
  79.  
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement