Advertisement
Guest User

LightTheTorches

a guest
Jul 13th, 2015
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.40 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. class LightTheTorches
  4. {
  5.     static void Main()
  6.     {
  7.         int darkRooms = 0;
  8.         int result = 0;
  9.         byte numberOfRooms = byte.Parse(Console.ReadLine());
  10.         string isLit = Console.ReadLine();
  11.         StringBuilder sb = new StringBuilder();
  12.         int index = 0;
  13.         for (int i = 0; i < numberOfRooms; i++)
  14.         {
  15.             sb.Append(isLit[index]);
  16.             if (index == isLit.Length - 1)
  17.             {
  18.                 index = 0;
  19.             }
  20.             else
  21.             {
  22.                 index++;
  23.             }
  24.         }
  25.         // Console.WriteLine(sb); // TEST
  26.         string[] values = new string[2];
  27.         string newDirection = "";
  28.         string oldDirection = "";
  29.         int distance = 0;
  30.         string move = "";
  31.         int priestPosition = numberOfRooms / 2;
  32.         while (true)
  33.         {
  34.            
  35.             move = Console.ReadLine();
  36.             if (move.Equals("END"))
  37.             {
  38.                 break;
  39.             }
  40.             else
  41.             {
  42.                 values = move.Split(' ');
  43.                 newDirection = values[0];
  44.                 if (numberOfRooms == 1)
  45.                 {
  46.                     if (sb[0].Equals('D'))
  47.                     {
  48.                         result = 68;
  49.                     }
  50.                     else
  51.                     {
  52.                         result = 0;
  53.                     }
  54.                     if (move.Equals("END"))
  55.                     {
  56.                         break;
  57.                     }
  58.                 }
  59.                 if (newDirection.Equals(oldDirection) && newDirection.Equals("LEFT"))
  60.                 {
  61.                     if (priestPosition == 0)
  62.                     {
  63.                         // Console.WriteLine(sb); // TEST
  64.                         continue;
  65.                     }
  66.                 }
  67.                 else if (newDirection.Equals(oldDirection) && newDirection.Equals("RIGHT"))
  68.                 {
  69.                     if (priestPosition == sb.Length - 1)
  70.                     {
  71.                         // Console.WriteLine(sb); // TEST
  72.                         continue;
  73.                     }
  74.                 }
  75.                 distance = int.Parse(values[1]);
  76.             }
  77.             if (newDirection.Equals("LEFT"))
  78.             {
  79.                 priestPosition -= (distance + 1);
  80.                 if (priestPosition < 0)
  81.                 {
  82.                     priestPosition = 0;
  83.                 }
  84.             }
  85.             else
  86.             {
  87.                 priestPosition += (distance + 1);
  88.                 if (priestPosition > sb.Length - 1)
  89.                 {
  90.                     priestPosition = sb.Length - 1;
  91.                 }
  92.             }
  93.             if (sb[priestPosition].Equals('L'))
  94.             {
  95.                 sb[priestPosition] = 'D';
  96.             }
  97.             else
  98.             {
  99.                 sb[priestPosition] = 'L';
  100.             }
  101.             oldDirection = newDirection;
  102.             // Console.WriteLine(sb); // TEST
  103.         }
  104.         // Console.WriteLine(sb); // TEST
  105.         darkRooms = 0;
  106.         for (int i = 0; i < sb.Length; i++)
  107.         {
  108.             if (sb[i].Equals('D'))
  109.             {
  110.                 darkRooms++;
  111.             }
  112.         }
  113.         if (numberOfRooms > 1)
  114.         {
  115.             result = darkRooms * 68;
  116.         }
  117.         Console.WriteLine(result);
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement