Advertisement
Guest User

Untitled

a guest
Nov 4th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.94 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 LightTheTorches
  8. {
  9.     class LightTheTorches
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int totalNumberOfRooms = int.Parse(Console.ReadLine());
  14.             char[] arr = new char[totalNumberOfRooms];
  15.            
  16.  
  17.             string lights = Console.ReadLine();
  18.             char[] lightsArr = lights.ToCharArray();
  19.  
  20.  
  21.             //fill the array with the information about which lights are lit
  22.             int lightsCounter = 0;
  23.             for (int i = 0; i < arr.Length; i++)
  24.             {
  25.                 arr[i] = lightsArr[lightsCounter];
  26.                 lightsCounter++;
  27.                 if (lightsCounter > lightsArr.Length - 1)
  28.                 {
  29.                     lightsCounter = 0;
  30.                 }
  31.             }
  32.  
  33.  
  34.             string commandsForThePriest = String.Empty;
  35.             int steps;
  36.             int currentPosition = totalNumberOfRooms / 2;
  37.             int lastPosition;
  38.             while (true)
  39.             {
  40.                 commandsForThePriest = Console.ReadLine();
  41.  
  42.                 if (commandsForThePriest == "END")
  43.                 {
  44.                     break;
  45.                 }
  46.  
  47.                 steps = int.Parse(commandsForThePriest.Split(' ')[1]) + 1;
  48.  
  49.                 if (commandsForThePriest.First() == 'R')
  50.                 {
  51.                     if (currentPosition + steps < arr.Length - 1)
  52.                     {
  53.                         lastPosition = currentPosition;
  54.                         currentPosition = currentPosition + steps;
  55.                         if (currentPosition != lastPosition)
  56.                         {
  57.                             arr[currentPosition] = changeLights(arr[currentPosition]);
  58.                         }
  59.                     }
  60.                     else if (currentPosition + steps >= arr.Length - 1 )
  61.                     {
  62.                         lastPosition = currentPosition;
  63.                         currentPosition = arr.Length - 1;
  64.                         if (currentPosition != lastPosition)
  65.                         {
  66.                             arr[currentPosition] = changeLights(arr[currentPosition]);
  67.                         }                      
  68.  
  69.                     }
  70.                 }
  71.                 else if (commandsForThePriest.First() == 'L')
  72.                 {
  73.                     if (currentPosition - steps > 0)
  74.                     {
  75.                         lastPosition = currentPosition;
  76.                         currentPosition = currentPosition - steps;
  77.                         if (currentPosition != lastPosition)
  78.                         {
  79.                             arr[currentPosition] = changeLights(arr[currentPosition]);
  80.                         }
  81.                        
  82.                     }
  83.                     else if (currentPosition - steps <= 0)
  84.                     {
  85.                         lastPosition = currentPosition;
  86.                         currentPosition = 0;
  87.                         if (currentPosition != lastPosition)
  88.                         {
  89.                             arr[currentPosition] = changeLights(arr[currentPosition]);
  90.                         }
  91.                        
  92.                     }
  93.                 }
  94.  
  95.             }
  96.  
  97.             int counterOfPrayers = 0;
  98.             for (int i = 0; i < arr.Length; i++)
  99.             {
  100.                 if (arr[i] == 'D')
  101.                 {
  102.                     counterOfPrayers++;
  103.                 }
  104.             }
  105.             int multiplier = 'D';
  106.  
  107.  
  108.             Console.WriteLine(counterOfPrayers * multiplier);
  109.  
  110.  
  111.  
  112.         }
  113.  
  114.         public static char changeLights(char c)
  115.         {
  116.             if (c == 'D')
  117.             {
  118.                 c = 'L';
  119.             }
  120.             else if (c == 'L')
  121.             {
  122.                 c = 'D';
  123.             }
  124.             return c;
  125.         }
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement