Advertisement
Guest User

Untitled

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