Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class LightTheTorches
- {
- public static List<int> torchedRooms = new List<int>();
- public static int nextReturnPosition = 0;
- static void Main()
- {
- int roomNumber = int.Parse(Console.ReadLine());
- string roomsInfo = Console.ReadLine();
- Rooms(roomNumber, roomsInfo);
- string command = Console.ReadLine();
- while (command != "END")
- {
- string[] monitoring = command.Split(' ');
- MonitoringMovement(monitoring, nextReturnPosition);
- command = Console.ReadLine();
- }
- Console.WriteLine(torchedRooms.Sum() * Convert.ToInt32('D'));
- }
- private static void Rooms(int num, string lightDark)
- {
- int updateRooms = 0;
- for (int i = 0; i < num; i++)
- {
- if (updateRooms > lightDark.Length - 1)
- {
- updateRooms = 0;
- }
- torchedRooms.Add(lightDark[updateRooms] == 'L' ? 0 : 1);
- updateRooms++;
- }
- nextReturnPosition = num / 2;
- }
- private static void MonitoringMovement(string[] arr, int startIndex)
- {
- int roomsToMonitor = Convert.ToInt32(arr[1]);
- if (arr[0] == "LEFT")
- {
- roomsToMonitor = startIndex - roomsToMonitor - 1;
- if (roomsToMonitor < 0)
- {
- roomsToMonitor = 0;
- }
- if (roomsToMonitor != startIndex)
- {
- torchedRooms[roomsToMonitor] = torchedRooms[roomsToMonitor] == 0 ? 1 : 0;
- }
- }
- if (arr[0] == "RIGHT")
- {
- roomsToMonitor = startIndex + roomsToMonitor + 1;
- if (roomsToMonitor >= torchedRooms.Count)
- {
- roomsToMonitor = torchedRooms.Count - 1;
- }
- if (roomsToMonitor != startIndex)
- {
- torchedRooms[roomsToMonitor] = torchedRooms[roomsToMonitor] == 0 ? 1 : 0;
- }
- }
- nextReturnPosition = roomsToMonitor;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement