Advertisement
Spiderbait90

Untitled

Apr 18th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.60 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.  
  7. namespace _01.Rabbit_Hole
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var str = Console.ReadLine().Split(' ').ToList();
  14.             var energy = int.Parse(Console.ReadLine());
  15.  
  16.             for (int i = 0; i < str.Count; i++)
  17.             {
  18.                 var splited = str[i].Split('|');
  19.                 if (splited[0] == "RabbitHole")
  20.                 {
  21.                     Console.WriteLine("You have 5 years to save Kennedy!");
  22.                     return;
  23.                 }
  24.                 else if (splited[0] == "Left")
  25.                 {
  26.                     var count = int.Parse(splited[1]);
  27.                     energy -= int.Parse(splited[1]);
  28.                     while (count > 0)
  29.                     {
  30.                         i--;
  31.                         count--;
  32.                         if (i == -1)
  33.                         {
  34.                             i = str.Count - 1;
  35.                         }
  36.                     }
  37.                     i -= 1;
  38.                 }
  39.                 else if (splited[0] == "Right")
  40.                 {
  41.                     var count = int.Parse(splited[1]);
  42.                     energy -= int.Parse(splited[1]);
  43.                     while (count > 0)
  44.                     {
  45.                         i++;
  46.                         count--;
  47.                         if (i == str.Count)
  48.                         {
  49.                             i = 0;
  50.                         }
  51.                     }
  52.                     i-=1;
  53.                 }
  54.                 else if (splited[0] == "Bomb")
  55.                 {
  56.                     energy -= int.Parse(splited[1]);
  57.                     str.RemoveAt(i);
  58.                     i = -1;
  59.                 }
  60.                 if (energy <= 0)
  61.                 {
  62.                     if (splited[0] == "Left" || splited[0] == "Right")
  63.                         Console.WriteLine("You are tired. You can't continue the mission.");
  64.                     else if (splited[0] == "Bomb")
  65.                         Console.WriteLine("You are dead due to bomb explosion!");
  66.                     return;
  67.                 }
  68.                 if (str[str.Count-1]=="RabbitHole")
  69.                 {
  70.                     str.Add($"Bomb|{energy}");
  71.                 }
  72.                 else if (str[str.Count - 1] != "RabbitHole")
  73.                 {
  74.                     str.RemoveAt(str.Count - 1);
  75.                     str.Add($"Bomb|{energy}");
  76.                 }
  77.  
  78.             }
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement