Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace LightTheTorches
- {
- class Program
- {
- public static void Main(string[] args)
- {
- int roomsInTheBasementInput = int.Parse(Console.ReadLine());
- int roomsInTheBasement = roomsInTheBasementInput;
- string lightOrDarkInput = Console.ReadLine();
- string lightAndDarkRooms = string.Empty;
- int letterCounter = 0;
- //updating the state of every single room in the basement
- while (roomsInTheBasementInput > 0)
- {
- if (letterCounter == lightOrDarkInput.Length)
- {
- letterCounter = 0;
- }
- char currentLetter = lightOrDarkInput[letterCounter];
- lightAndDarkRooms += currentLetter;
- letterCounter++;
- roomsInTheBasementInput--;
- }
- //getting commands for the movement of the priest and updating room Light/Dark status
- string command = string.Empty;
- string wayToWalk = string.Empty;
- string futureLightAndDarkRooms = string.Empty;
- string currentLightAndDarkRooms = string.Empty;
- int roomsToWalk = 0;
- int currentPosition = (lightAndDarkRooms.Length / 2);
- int futurePosition = 0;
- while (true)
- {
- command = Console.ReadLine();
- if (command != "END")
- {
- string[] movement = command.Split(' ');
- wayToWalk = movement[0];
- roomsToWalk = int.Parse(movement[1]);
- //getting the position that the priest must be at
- switch (wayToWalk)
- {
- case "LEFT": if (roomsToWalk > currentPosition)
- {
- futurePosition = 0;
- }
- else
- {
- futurePosition = (currentPosition - (roomsToWalk + 1));
- }
- ; break;
- case "RIGHT": if (roomsToWalk > currentPosition)
- {
- futurePosition = (lightAndDarkRooms.Length - 2);
- }
- else
- {
- futurePosition = (currentPosition + (roomsToWalk + 1));
- }
- ; break;
- }
- currentPosition = futurePosition;
- //walking from room to room and updating the room status
- futureLightAndDarkRooms = string.Empty;
- for (int currentRoom = 0; currentRoom < lightAndDarkRooms.Length; currentRoom++)
- {
- char room = lightAndDarkRooms[currentRoom];
- if (currentRoom == futurePosition && room == 'L')
- {
- futureLightAndDarkRooms += 'D';
- }
- else if (currentRoom == futurePosition && room == 'D')
- {
- futureLightAndDarkRooms += 'L';
- }
- else if (currentRoom != futurePosition)
- {
- futureLightAndDarkRooms += room;
- }
- }
- lightAndDarkRooms = futureLightAndDarkRooms;
- }
- else
- {
- break;
- }
- }
- int darkRooms = 0;
- char d = 'D';
- int asciiCodeOfD = (int)d;
- for (int currentRoom = 0; currentRoom < futureLightAndDarkRooms.Length; currentRoom++)
- {
- char room = futureLightAndDarkRooms[currentRoom];
- if (room == 'D')
- {
- darkRooms++;
- }
- }
- Console.WriteLine(darkRooms * asciiCodeOfD);
- }
- }
- }
Add Comment
Please, Sign In to add comment