Created
July 14, 2015 19:43
-
-
Save zdgeorgiev/56f6692e3bc5c04c6782 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int roomSize = int.Parse(Console.ReadLine()); | |
string roomFilter = Console.ReadLine(); | |
StringBuilder room = new StringBuilder(); | |
for (int i = 0; i < roomSize; i++) | |
{ | |
room.Append(roomFilter[i % roomFilter.Length]); | |
} | |
string currentCommand = Console.ReadLine(); | |
int currentPriestPosition = roomSize / 2; | |
int darkRoomsCount = 0; | |
while (currentCommand != "END") | |
{ | |
int lastPriestPosition = currentPriestPosition; | |
switch (currentCommand.Split(' ')[0]) | |
{ | |
case "LEFT": | |
int stepLeft = int.Parse(currentCommand.Split(' ')[1]); | |
for (int i = 1; i <= stepLeft + 1; i++) | |
{ | |
if (lastPriestPosition - 1 >= 0) | |
{ | |
lastPriestPosition--; | |
} | |
else | |
{ | |
break; | |
} | |
} | |
if (currentPriestPosition != lastPriestPosition) | |
{ | |
currentPriestPosition = lastPriestPosition; | |
ChangeRoomState(currentPriestPosition, ref room); | |
} | |
break; | |
case "RIGHT": | |
int stepRight = int.Parse(currentCommand.Split(' ')[1]); | |
for (int i = 1; i <= stepRight + 1; i++) | |
{ | |
if (lastPriestPosition + 1 < roomSize) | |
{ | |
lastPriestPosition++; | |
} | |
else | |
{ | |
break; | |
} | |
} | |
if (currentPriestPosition != lastPriestPosition) | |
{ | |
currentPriestPosition = lastPriestPosition; | |
ChangeRoomState(currentPriestPosition, ref room); | |
} | |
break; | |
default: | |
break; | |
} | |
currentCommand = Console.ReadLine(); | |
} | |
for (int i = 0; i < room.Length; i++) | |
{ | |
if (room[i] == 'D') | |
{ | |
darkRoomsCount++; | |
} | |
} | |
Console.WriteLine(darkRoomsCount * 68); | |
} | |
private static void ChangeRoomState(int currentPriestPosition, ref StringBuilder room) | |
{ | |
if (room[currentPriestPosition] == 'L') | |
{ | |
room[currentPriestPosition] = 'D'; | |
} | |
else | |
{ | |
room[currentPriestPosition] = 'L'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment