Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _10._Radioactive_Mutant_Bunnies
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] dimensions = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- int rows = dimensions[0];
- int columns = dimensions[1];
- char[,] matrix = new char[rows, columns];
- int currentRow = 0;
- int currentCol = 0;
- bool isDead = false;
- bool isOutside = false;
- for (int i = 0; i < rows; i++)
- {
- string values = Console.ReadLine();
- for (int j = 0; j < columns; j++)
- {
- matrix[i, j] = values[j];
- if (matrix[i, j] == 'P')
- {
- currentRow = i;
- currentCol = j;
- }
- }
- }
- string commands = Console.ReadLine();
- for (int i = 0; i < commands.Length; i++)
- {
- if (commands[i] == 'U')
- {
- if (currentRow - 1 >= 0)
- {
- if (matrix[currentRow - 1, currentCol] == '.')
- {
- matrix[currentRow, currentCol] = '.';
- currentRow = currentRow - 1;
- matrix[currentRow, currentCol] = 'P';
- }
- else if (matrix[currentRow - 1, currentCol] == 'B')
- {
- currentRow = currentRow - 1;
- isDead = true;
- }
- }
- else
- {
- matrix[currentRow, currentCol] = '.';
- isOutside = true;
- }
- }
- if (commands[i] == 'D')
- {
- if (currentRow + 1 < rows)
- {
- if (matrix[currentRow + 1, currentCol] == '.')
- {
- matrix[currentRow, currentCol] = '.';
- currentRow = currentRow + 1;
- matrix[currentRow, currentCol] = 'P';
- }
- else if (matrix[currentRow + 1, currentCol] == 'B')
- {
- currentRow = currentRow + 1;
- isDead = true;
- }
- }
- else
- {
- matrix[currentRow, currentCol] = '.';
- isOutside = true;
- }
- }
- if (commands[i] == 'L')
- {
- if (currentCol - 1 >= 0)
- {
- if (matrix[currentRow, currentCol - 1] == '.')
- {
- matrix[currentRow, currentCol] = '.';
- currentCol = currentCol - 1;
- matrix[currentRow, currentCol] = 'P';
- }
- else if (matrix[currentRow, currentCol - 1] == 'B')
- {
- currentCol = currentCol - 1;
- isDead = true;
- }
- }
- else
- {
- matrix[currentRow, currentCol] = '.';
- isOutside = true;
- }
- }
- if (commands[i] == 'R')
- {
- if (currentCol + 1 < rows)
- {
- if (matrix[currentRow, currentCol + 1] == '.')
- {
- matrix[currentRow, currentCol] = '.';
- currentCol = currentCol + 1;
- matrix[currentRow, currentCol] = 'P';
- }
- else if (matrix[currentRow, currentCol + 1] == 'B')
- {
- currentCol = currentCol + 1;
- isDead = true;
- }
- }
- else
- {
- matrix[currentRow, currentCol] = '.';
- isOutside = true;
- }
- }
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < columns; col++)
- {
- if (matrix[row, col] == 'B')
- {
- //UP
- if (row - 1 >= 0)
- {
- if (matrix[row - 1, col] == 'P')
- {
- matrix[row - 1, col] = 'B';
- isDead = true;
- }
- else if (matrix[row - 1, col] == '.')
- {
- matrix[row - 1, col] = 'A';
- }
- }
- //DOWN
- if (row + 1 < rows)
- {
- if (matrix[row + 1, col] == 'P')
- {
- matrix[row + 1, col] = 'B';
- isDead = true;
- }
- else if (matrix[row + 1, col] == '.')
- {
- matrix[row + 1, col] = 'A';
- }
- }
- //LEFT
- if (col - 1 >= 0)
- {
- if (matrix[row, col - 1] == 'P')
- {
- matrix[row, col - 1] = 'B';
- isDead = true;
- }
- else if (matrix[row, col - 1] == '.')
- {
- matrix[row, col - 1] = 'A';
- }
- }
- //RIGHT
- if (col + 1 < rows)
- {
- if (matrix[row, col + 1] == 'P')
- {
- matrix[row, col + 1] = 'B';
- isDead = true;
- }
- else if (matrix[row, col + 1] == '.')
- {
- matrix[row, col + 1] = 'A';
- }
- }
- }
- }
- }
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < columns; col++)
- {
- if (matrix[row, col] == 'A')
- {
- matrix[row, col] = 'B';
- }
- }
- }
- if (isDead == true || isOutside == true)
- {
- break;
- }
- }
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < columns; j++)
- {
- Console.Write($"{matrix[i, j]}");
- }
- Console.WriteLine();
- }
- if (isDead)
- {
- Console.WriteLine($"dead: {currentRow} {currentCol}");
- }
- if (isOutside)
- {
- Console.WriteLine($"won: {currentRow} {currentCol}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement