Advertisement
Mitax

01.Rabbit_Hole

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