Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- //You are trying to go back in the past to prevent Kennedy’s assassination. But first you should find the rabbit hole. Your energy is //limited and if you exhaust it, you will be tired and can’t continue the mission.
- //You will be given an array of strings representing different obstacles you should overcome.
- //• “Left|[integer value]”-you should jump to the left with [integer value] positions and decrease your energy with [integer value];
- //• “Right|[integer value]”-you should jump to the right with [integer value] positions and decrease your energy with [integer value];
- //• “Bomb|[integer value]”-the bomb explodes and this element of the array should be removed, your energy should be decreased be the //[integer value], you should start from the beginning (index 0);
- //• “RabbitHole” – you have found the rabbit hole, the program should stop here, print on the console – “You have 5 years to save //Kennedy!”
- namespace hole
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> command = Console.ReadLine().Split(' ').ToList();
- int energy = int.Parse(Console.ReadLine());
- int currentIndex = 0;
- bool deadByBomb = false;
- while (energy > 0)
- {
- deadByBomb = false;
- string[] currentCommand = command[currentIndex].Split('|');
- string action = currentCommand[0];
- if (action == "RabbitHole")
- {
- Console.WriteLine("You have 5 years to save Kennedy!");
- break;
- }
- int value = int.Parse(currentCommand[1]);
- switch (action)
- {
- case "Left":
- currentIndex = Math.Abs(currentIndex - value) % command.Count;
- energy -= value;
- break;
- case "Right":
- currentIndex = (currentIndex + value) % command.Count;
- energy -= value;
- break;
- case "Bomb":
- command.RemoveAt(currentIndex);
- currentIndex = 0;
- energy -= value;
- deadByBomb = true;
- break;
- }
- if (command[command.Count - 1] != "RabbitHole")
- {
- command.RemoveAt(command.Count - 1);
- }
- command.Add("Bomb|" + energy);
- if (energy <= 0 && deadByBomb)
- {
- Console.WriteLine("You are dead due to bomb explosion!");
- }
- else if (energy <= 0 && !deadByBomb)
- {
- Console.WriteLine("You are tired. You can't continue the mission.");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement