simonradev

asd

Nov 22nd, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | None | 0 0
  1. using System;
  2.  
  3. namespace LightTheTorches
  4. {
  5.     class Program
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             int roomsInTheBasementInput = int.Parse(Console.ReadLine());
  10.             int roomsInTheBasement = roomsInTheBasementInput;
  11.            
  12.             string lightOrDarkInput = Console.ReadLine();
  13.             string lightAndDarkRooms = string.Empty;
  14.             int letterCounter = 0;
  15.            
  16.             //updating the state of every single room in the basement
  17.             while (roomsInTheBasementInput > 0)
  18.             {
  19.                 if (letterCounter == lightOrDarkInput.Length)
  20.                 {
  21.                     letterCounter = 0;
  22.                 }
  23.                
  24.                 char currentLetter = lightOrDarkInput[letterCounter];
  25.                 lightAndDarkRooms += currentLetter;
  26.                
  27.                 letterCounter++;
  28.                 roomsInTheBasementInput--;
  29.             }
  30.            
  31.             //getting commands for the movement of the priest and updating room Light/Dark status
  32.             string command = string.Empty;
  33.             string wayToWalk = string.Empty;
  34.             string futureLightAndDarkRooms = string.Empty;
  35.             string currentLightAndDarkRooms = string.Empty;
  36.             int roomsToWalk = 0;
  37.             int currentPosition = (lightAndDarkRooms.Length / 2);
  38.             int futurePosition = 0;
  39.             while (true)
  40.             {
  41.                 command = Console.ReadLine();
  42.                
  43.                 if (command != "END")
  44.                 {
  45.                     string[] movement = command.Split(' ');
  46.                     wayToWalk = movement[0];
  47.                     roomsToWalk = int.Parse(movement[1]);
  48.                    
  49.                     //getting the position that the priest must be at
  50.                     switch (wayToWalk)
  51.                     {
  52.                             case "LEFT": if (roomsToWalk > currentPosition)
  53.                                          {
  54.                                             futurePosition = 0;
  55.                                          }
  56.                                          else
  57.                                          {
  58.                                             futurePosition = (currentPosition - (roomsToWalk + 1));
  59.                                          }
  60.                                          ; break;
  61.                             case "RIGHT": if (roomsToWalk > currentPosition)
  62.                                           {
  63.                                              futurePosition = (lightAndDarkRooms.Length - 2);
  64.                                           }
  65.                                           else
  66.                                           {
  67.                                              futurePosition = (currentPosition + (roomsToWalk + 1));
  68.                                           }
  69.                                           ; break;
  70.                     }
  71.                     currentPosition = futurePosition;
  72.                    
  73.                     //walking from room to room and updating the room status
  74.                     futureLightAndDarkRooms = string.Empty;
  75.                     for (int currentRoom = 0; currentRoom < lightAndDarkRooms.Length; currentRoom++)
  76.                     {
  77.                         char room = lightAndDarkRooms[currentRoom];
  78.                        
  79.                         if (currentRoom == futurePosition && room == 'L')
  80.                         {
  81.                             futureLightAndDarkRooms += 'D';
  82.                         }
  83.                         else if (currentRoom == futurePosition && room == 'D')
  84.                         {
  85.                             futureLightAndDarkRooms += 'L';
  86.                         }
  87.                         else if (currentRoom != futurePosition)
  88.                         {
  89.                             futureLightAndDarkRooms += room;
  90.                         }
  91.                     }
  92.                     lightAndDarkRooms = futureLightAndDarkRooms;
  93.                 }
  94.                 else
  95.                 {
  96.                     break;
  97.                 }
  98.             }
  99.            
  100.             int darkRooms = 0;
  101.             char d = 'D';
  102.             int asciiCodeOfD = (int)d;
  103.             for (int currentRoom = 0; currentRoom < futureLightAndDarkRooms.Length; currentRoom++)
  104.             {
  105.                 char room = futureLightAndDarkRooms[currentRoom];
  106.                
  107.                 if (room == 'D')
  108.                 {
  109.                     darkRooms++;
  110.                 }
  111.             }
  112.            
  113.             Console.WriteLine(darkRooms * asciiCodeOfD);
  114.            
  115.         }
  116.     }
  117. }
Add Comment
Please, Sign In to add comment