Advertisement
Guest User

Untitled

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