Advertisement
ViktorMarinov

04.Light The Torches

Jul 14th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.28 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.  
  8. class LightTheTorches
  9. {
  10.     static void Main()
  11.     {
  12.         int n = int.Parse(Console.ReadLine());
  13.         string lightOrDark = Console.ReadLine();
  14.         List<string> commands = new List<string>();
  15.         do
  16.         {
  17.             string temp = Console.ReadLine();
  18.             commands.Add(temp);
  19.         } while (commands[commands.Count - 1] != "END");
  20.  
  21.         char[] rooms = new char[n];
  22.         int lightDarkCount = 0;
  23.         for (int i = 0; i < rooms.Length; i++)
  24.         {
  25.             rooms[i] = lightOrDark[lightDarkCount++];
  26.             if (lightDarkCount == lightOrDark.Length)
  27.             {
  28.                 lightDarkCount = 0;
  29.             }
  30.         }
  31.  
  32.         int fatherPosition = n / 2;
  33.         int direction = 0;
  34.         int roomsToSkip = 0;
  35.         while (commands[0] != "END")
  36.         {
  37.             if (commands[0].Substring(0, 4) == "LEFT")
  38.             {
  39.                 direction = -1;
  40.                 roomsToSkip = int.Parse(commands[0].Substring(5));
  41.             }
  42.             else
  43.             {
  44.                 direction = 1;
  45.                 roomsToSkip = int.Parse(commands[0].Substring(6));
  46.             }
  47.             if (fatherPosition == 0 && direction < 0 || fatherPosition == n - 1 && direction > 0)
  48.             {
  49.                 commands.RemoveAt(0);
  50.                 continue;
  51.             }
  52.  
  53.             if (direction < 0)
  54.             {
  55.                 fatherPosition = fatherPosition - ( roomsToSkip + 1);
  56.                 if (fatherPosition < 0)
  57.                     fatherPosition = 0;
  58.             }
  59.             else
  60.             {
  61.                 fatherPosition = fatherPosition + (roomsToSkip + 1);
  62.                 if (fatherPosition >= n)
  63.                     fatherPosition = n - 1;
  64.             }
  65.            
  66.             if (rooms[fatherPosition] == 'D')
  67.                 rooms[fatherPosition] = 'L';
  68.             else
  69.                 rooms[fatherPosition] = 'D';
  70.            
  71.             commands.RemoveAt(0);
  72.         }
  73.  
  74.         int countD = 0;
  75.         foreach (var item in rooms)
  76.         {
  77.             if (item == 'D')
  78.                 countD++;
  79.         }
  80.  
  81.         Console.WriteLine('D' * countD);
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement