Advertisement
Guest User

Untitled

a guest
May 3rd, 2017
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01.RabbitHole
  6. {
  7. public class RabbitHole
  8. {
  9. public static void Main()
  10. {
  11. List<string> obstacles = Console.ReadLine().Split(' ').ToList();
  12. int energy = int.Parse(Console.ReadLine());
  13.  
  14. bool bombExplosion = false;
  15. string currentObstacle = obstacles.First();
  16. int position = 0;
  17.  
  18. while (true)
  19. {
  20. currentObstacle = obstacles[position];
  21.  
  22. if (energy <= 0 && bombExplosion)
  23. {
  24. Console.WriteLine("You are dead due to bomb explosion!");
  25. break;
  26. }
  27.  
  28. if (energy <= 0)
  29. {
  30. Console.WriteLine("You are tired. You can't continue the mission.");
  31. break;
  32. }
  33.  
  34. if (currentObstacle.ToLower() == "rabbithole")
  35. {
  36. Console.WriteLine("You have 5 years to save Kennedy!");
  37. break;
  38. }
  39.  
  40. string[] currentObstacleElements = currentObstacle.Split('|');
  41. string direction = currentObstacleElements[0];
  42. int jumps = int.Parse(currentObstacleElements[1]);
  43.  
  44. bombExplosion = false;
  45.  
  46. switch (direction.ToLower())
  47. {
  48. case "right":
  49. position += jumps % obstacles.Count;
  50.  
  51. //if (position >= obstacles.Count)
  52. //{
  53. // position -= obstacles.Count;
  54. //}
  55.  
  56. break;
  57.  
  58. case "left":
  59. position -= jumps % obstacles.Count;
  60. position = Math.Abs(position);
  61.  
  62. //if (position < 0)
  63. //{
  64. // position += obstacles.Count;
  65. //}
  66.  
  67. break;
  68.  
  69. case "bomb":
  70. obstacles.RemoveAt(position);
  71. position = 0;
  72. bombExplosion = true;
  73. break;
  74. }
  75.  
  76. energy -= jumps;
  77.  
  78. if (obstacles.Last().ToLower() != "rabbithole")
  79. {
  80. obstacles.RemoveAt(obstacles.Count - 1);
  81. }
  82.  
  83. obstacles.Add(string.Format($"Bomb|{energy}"));
  84. }
  85. }
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement