Advertisement
fbinnzhivko

04.01 Light the Torches

May 4th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 KB | None | 0 0
  1. using System;
  2. class LightTheTorches
  3. {
  4.     static void Main()
  5.     {
  6.         int n = int.Parse(Console.ReadLine());
  7.         string ld = Console.ReadLine();
  8.         char[] rooms = new char[n];
  9.         for (int i = 0, j = 0; i < n; i++)
  10.         {
  11.             rooms[i] = ld[j];
  12.             j++;
  13.             if (j >= ld.Length)
  14.             {
  15.                 j = 0;
  16.             }
  17.         }
  18.         int startPos = n / 2;
  19.         string command = Console.ReadLine();
  20.         while (command != "END")
  21.         {
  22.             string[] currCommand = command.Split();
  23.             int move = int.Parse(currCommand[1]);
  24.  
  25.             if (currCommand[0] == "LEFT")
  26.             {
  27.                 move = startPos - move - 1;
  28.                 if (move < 0)
  29.                 {
  30.                     move = 0;
  31.                 }
  32.                 if (move != startPos)
  33.                 {
  34.                     if (rooms[move] == 'L')
  35.                     {
  36.                         rooms[move] = 'D';
  37.                     }
  38.                     else
  39.                     {
  40.                         rooms[move] = 'L';
  41.                     }
  42.                 }
  43.             }
  44.             if (currCommand[0] == "RIGHT")
  45.             {
  46.                 move = startPos + move + 1;
  47.                 if (move >= rooms.Length)
  48.                 {
  49.                     move = rooms.Length - 1;
  50.                 }
  51.                 if (move != startPos)
  52.                 {
  53.                     if (rooms[move] == 'L')
  54.                     {
  55.                         rooms[move] = 'D';
  56.                     }
  57.                     else
  58.                     {
  59.                         rooms[move] = 'L';
  60.                     }
  61.                 }
  62.             }
  63.             startPos = move;
  64.             command = Console.ReadLine();
  65.         }
  66.         int count = 0;
  67.         for (int i = 0; i < rooms.Length; i++)
  68.         {
  69.             if (rooms[i] == 'D')
  70.             {
  71.                 count++;
  72.             }
  73.         }
  74.         int prays = 'D' * count;
  75.  
  76.         Console.WriteLine(prays);
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement