Advertisement
grubcho

Rabbit hole

Jul 3rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.10 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. //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.
  7. //You will be given an array of strings representing different obstacles you should overcome.
  8. //•   “Left|[integer value]”-you should jump to the left with [integer value] positions and decrease your energy with [integer value];
  9. //•   “Right|[integer value]”-you should jump to the right with [integer value] positions and decrease your energy with [integer value];
  10. //•   “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);
  11. //•   “RabbitHole” – you have found the rabbit hole, the program should stop here, print on the console – “You have 5 years to save //Kennedy!”
  12.  
  13. namespace hole
  14. {
  15.     class Program
  16.     {
  17.         static void Main(string[] args)
  18.         {
  19.             List<string> command = Console.ReadLine().Split(' ').ToList();
  20.             int energy = int.Parse(Console.ReadLine());
  21.  
  22.             int currentIndex = 0;
  23.             bool deadByBomb = false;
  24.  
  25.             while (energy > 0)
  26.             {
  27.                 deadByBomb = false;
  28.                 string[] currentCommand = command[currentIndex].Split('|');
  29.                 string action = currentCommand[0];
  30.  
  31.                 if (action == "RabbitHole")
  32.                 {
  33.                     Console.WriteLine("You have 5 years to save Kennedy!");
  34.                     break;
  35.                 }
  36.  
  37.                 int value = int.Parse(currentCommand[1]);
  38.  
  39.                 switch (action)
  40.                 {
  41.  
  42.                     case "Left":
  43.                         currentIndex = Math.Abs(currentIndex - value) % command.Count;
  44.                         energy -= value;
  45.                         break;
  46.  
  47.                     case "Right":
  48.                         currentIndex = (currentIndex + value) % command.Count;
  49.                         energy -= value;
  50.                         break;
  51.  
  52.                     case "Bomb":
  53.                         command.RemoveAt(currentIndex);
  54.                         currentIndex = 0;
  55.                         energy -= value;
  56.                         deadByBomb = true;
  57.                         break;
  58.                 }
  59.  
  60.                 if (command[command.Count - 1] != "RabbitHole")
  61.                 {
  62.                     command.RemoveAt(command.Count - 1);
  63.                 }
  64.                 command.Add("Bomb|" + energy);
  65.  
  66.  
  67.                 if (energy <= 0 && deadByBomb)
  68.                 {
  69.                     Console.WriteLine("You are dead due to bomb explosion!");
  70.                 }
  71.                 else if (energy <= 0 && !deadByBomb)
  72.                 {
  73.                     Console.WriteLine("You are tired. You can't continue the mission.");
  74.                 }
  75.             }
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement