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;
- namespace TrophonTheGrumpyCat
- {
- class Program
- {
- static void Main(string[] args)
- {
- int matrixRowsCount = int.Parse(Console.ReadLine());
- List<string> matrix = new List<string>();
- int currentCol = 0;
- int currentRow = 0;
- for (int i = 0; i < matrixRowsCount; i++)
- {
- matrix.Add(Console.ReadLine());
- if (matrix[i].Contains("S"))
- {
- currentRow = i;
- currentCol = matrix[i].IndexOf("S");
- }
- }
- string directions = Console.ReadLine();
- int turns = 0;
- for (int i = 0; i < directions.Length; i++)
- {
- turns++;
- char move = directions[i];
- switch (move)
- {
- case 'D':
- while (true)
- {
- currentRow++;
- if (currentRow == matrix.Count())
- {
- currentRow = 0;
- if (currentCol >= matrix[currentRow].Length)
- {
- continue;
- }
- else
- {
- break;
- }
- }
- if (currentCol >= matrix[currentRow].Length)
- {
- continue;
- }
- else
- {
- break;
- }
- }
- break;
- case 'U':
- while (true)
- {
- currentRow--;
- if (currentRow == -1)
- {
- currentRow = matrix.Count() - 1;
- if (currentCol >= matrix[currentRow].Length)
- {
- continue;
- }
- else
- {
- break;
- }
- }
- if (currentCol >= matrix[currentRow].Length)
- {
- continue;
- }
- else
- {
- break;
- }
- }
- break;
- case 'L':
- currentCol--;
- if (currentCol == -1)
- {
- currentCol = matrix[currentRow].Length - 1;
- }
- break;
- case 'R':
- currentCol++;
- if (currentCol== matrix[currentRow].Length)
- {
- currentCol = 0;
- }
- break;
- }
- if (matrix[currentRow][currentCol] == 'E')
- {
- Console.WriteLine("Experiment successful. {0} turns required.", turns);
- return;
- }
- }
- Console.WriteLine("Robot stuck at {0} {1}. Experiment failed.", currentRow, currentCol);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment