Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class LightTheTorches
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- string lightOrDark = Console.ReadLine();
- List<string> commands = new List<string>();
- do
- {
- string temp = Console.ReadLine();
- commands.Add(temp);
- } while (commands[commands.Count - 1] != "END");
- char[] rooms = new char[n];
- int lightDarkCount = 0;
- for (int i = 0; i < rooms.Length; i++)
- {
- rooms[i] = lightOrDark[lightDarkCount++];
- if (lightDarkCount == lightOrDark.Length)
- {
- lightDarkCount = 0;
- }
- }
- int fatherPosition = n / 2;
- int direction = 0;
- int roomsToSkip = 0;
- while (commands[0] != "END")
- {
- if (commands[0].Substring(0, 4) == "LEFT")
- {
- direction = -1;
- roomsToSkip = int.Parse(commands[0].Substring(5));
- }
- else
- {
- direction = 1;
- roomsToSkip = int.Parse(commands[0].Substring(6));
- }
- if (fatherPosition == 0 && direction < 0 || fatherPosition == n - 1 && direction > 0)
- {
- commands.RemoveAt(0);
- continue;
- }
- if (direction < 0)
- {
- fatherPosition = fatherPosition - ( roomsToSkip + 1);
- if (fatherPosition < 0)
- fatherPosition = 0;
- }
- else
- {
- fatherPosition = fatherPosition + (roomsToSkip + 1);
- if (fatherPosition >= n)
- fatherPosition = n - 1;
- }
- if (rooms[fatherPosition] == 'D')
- rooms[fatherPosition] = 'L';
- else
- rooms[fatherPosition] = 'D';
- commands.RemoveAt(0);
- }
- int countD = 0;
- foreach (var item in rooms)
- {
- if (item == 'D')
- countD++;
- }
- Console.WriteLine('D' * countD);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement