fbinnzhivko

04.00 Light the Torches

May 4th, 2016
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.34 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class LightTheTorches
  5. {
  6.     static void Main()
  7.     {
  8.         int numberOfRooms = int.Parse(Console.ReadLine());
  9.         string lightOrDark = Console.ReadLine();
  10.         char[] basement = new char[numberOfRooms];
  11.         int count = 0;
  12.         for (int i = 0; i < basement.Length; i++)
  13.         {
  14.             basement[i] = lightOrDark[count];
  15.             count++;
  16.             if (count == lightOrDark.Length)
  17.             {
  18.                 count = 0;
  19.             }
  20.         }
  21.         string[] command = Console.ReadLine().Split(' ').ToArray();
  22.         int curentPosition = numberOfRooms / 2;
  23.         while (command[0] != "END")
  24.         {
  25.             if (command[0] == "RIGHT")
  26.             {
  27.                 if (curentPosition != basement.Length - 1)
  28.                 {
  29.                     if ((int.Parse(command[1]) + 2) + curentPosition < basement.Length)
  30.                     {
  31.                         curentPosition += (int.Parse(command[1]) + 1);
  32.                         if (basement[curentPosition] == 'L')
  33.                         {
  34.                             basement[curentPosition] = 'D';
  35.                         }
  36.                         else if (basement[curentPosition] == 'D')
  37.                         {
  38.                             basement[curentPosition] = 'L';
  39.                         }
  40.                     }
  41.                     else
  42.                     {
  43.                         curentPosition = numberOfRooms - 1;
  44.                         if (basement[curentPosition] == 'L')
  45.                         {
  46.                             basement[curentPosition] = 'D';
  47.                         }
  48.                         else if (basement[curentPosition] == 'D')
  49.                         {
  50.                             basement[curentPosition] = 'L';
  51.                         }
  52.                     }
  53.                 }
  54.             }
  55.             else
  56.             {
  57.                 if (curentPosition != 0)
  58.                 {
  59.                     if (curentPosition - (int.Parse(command[1]) + 2) >= 0)
  60.                     {
  61.                         curentPosition -= (int.Parse(command[1]) + 1);
  62.                         if (basement[curentPosition] == 'L')
  63.                         {
  64.                             basement[curentPosition] = 'D';
  65.                         }
  66.                         else if (basement[curentPosition] == 'D')
  67.                         {
  68.                             basement[curentPosition] = 'L';
  69.                         }
  70.                     }
  71.                     else
  72.                     {
  73.                         curentPosition = 0;
  74.                         if (basement[curentPosition] == 'L')
  75.                         {
  76.                             basement[curentPosition] = 'D';
  77.                         }
  78.                         else if (basement[curentPosition] == 'D')
  79.                         {
  80.                             basement[curentPosition] = 'L';
  81.                         }
  82.                     }
  83.                 }
  84.             }
  85.             command = Console.ReadLine().Split(' ').ToArray();
  86.         }
  87.         int prays = 0;
  88.         for (int i = 0; i < basement.Length; i++)
  89.         {
  90.             if (basement[i] == 'D')
  91.             {
  92.                 prays++;
  93.             }
  94.         }
  95.         long print = prays * 68;
  96.         Console.WriteLine(print);
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment