Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _01.RabbitHole
- {
- public class RabbitHole
- {
- public static void Main()
- {
- List<string> obstacles = Console.ReadLine().Split(' ').ToList();
- int energy = int.Parse(Console.ReadLine());
- bool bombExplosion = false;
- string currentObstacle = obstacles.First();
- int position = 0;
- while (true)
- {
- currentObstacle = obstacles[position];
- if (energy <= 0 && bombExplosion)
- {
- Console.WriteLine("You are dead due to bomb explosion!");
- break;
- }
- if (energy <= 0)
- {
- Console.WriteLine("You are tired. You can't continue the mission.");
- break;
- }
- if (currentObstacle.ToLower() == "rabbithole")
- {
- Console.WriteLine("You have 5 years to save Kennedy!");
- break;
- }
- string[] currentObstacleElements = currentObstacle.Split('|');
- string direction = currentObstacleElements[0];
- int jumps = int.Parse(currentObstacleElements[1]);
- bombExplosion = false;
- switch (direction.ToLower())
- {
- case "right":
- position += jumps % obstacles.Count;
- //if (position >= obstacles.Count)
- //{
- // position -= obstacles.Count;
- //}
- break;
- case "left":
- position -= jumps % obstacles.Count;
- position = Math.Abs(position);
- //if (position < 0)
- //{
- // position += obstacles.Count;
- //}
- break;
- case "bomb":
- obstacles.RemoveAt(position);
- position = 0;
- bombExplosion = true;
- break;
- }
- energy -= jumps;
- if (obstacles.Last().ToLower() != "rabbithole")
- {
- obstacles.RemoveAt(obstacles.Count - 1);
- }
- obstacles.Add(string.Format($"Bomb|{energy}"));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement