Advertisement
simeon3000

02. Icarus

Sep 6th, 2017
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1.             int[] thePlane = Console.ReadLine()
  2.                 .Split().Select(int.Parse).ToArray();
  3.  
  4.             int index = int.Parse(Console.ReadLine());
  5.  
  6.             int damage = 1;
  7.  
  8.             string command = Console.ReadLine();
  9.             while (command != "Supernova")
  10.             {
  11.                 string[] myArr = command.Split();
  12.                 string direction = myArr[0];
  13.                 int steps = int.Parse(myArr[1]);
  14.  
  15.                 switch (direction)
  16.                 {
  17.                     case "left":
  18.  
  19.                         for (int i = 0; i < steps; i++)
  20.                         {
  21.                             index--;
  22.  
  23.                             if (index < 0)
  24.                             {
  25.                                 index = thePlane.Length - 1;
  26.                                 damage++;
  27.                             }
  28.  
  29.                             thePlane[index] -= damage;
  30.                         }
  31.  
  32.                         break;
  33.  
  34.                     case "right":
  35.  
  36.                         for (int i = 0; i < steps; i++)
  37.                         {
  38.                             index++;
  39.  
  40.                             if (index > thePlane.Length - 1)
  41.                             {
  42.                                 index = 0;
  43.                                 damage++;
  44.                             }
  45.  
  46.                             thePlane[index] -= damage;
  47.                         }
  48.  
  49.                         break;
  50.                        
  51.                 }
  52.  
  53.                 command = Console.ReadLine();
  54.             }
  55.  
  56.             Console.WriteLine(string.Join(" ", thePlane));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement