Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace LadyBugs
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] indices = Console.ReadLine().Split(' ');
- int rows = int.Parse(indices[0]);
- int cols = int.Parse(indices[1]);
- int playerRow = 0;
- int playerCol = 0;
- char[,] matrix = new char[rows, cols];
- for (int row = 0; row < rows; row++)
- {
- string line = Console.ReadLine();
- for (int col = 0; col < cols; col++)
- {
- matrix[row, col] = line[col];
- if (line[col] == 'P')
- {
- playerRow = row;
- playerCol = col;
- matrix[row, col] = '.';
- }
- }
- }
- string commands = Console.ReadLine();
- for (int i = 0; i < commands.Length; i++)
- {
- string prev = playerRow + " " + playerCol;
- switch (commands[i])
- {
- case 'L':
- playerCol--; break;
- case 'U':
- playerRow--; break;
- case 'R':
- playerCol++; break;
- case 'D':
- playerRow++; break;
- }
- char[,] updatedMatrix = (char[,]) matrix.Clone();
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- if (matrix[row, col] == 'B')
- {
- if (isInside(row - 1, col, matrix))
- {
- updatedMatrix[row - 1, col] = 'B';
- }
- if (isInside(row + 1, col, matrix))
- {
- updatedMatrix[row + 1, col] = 'B';
- }
- if (isInside(row, col - 1, matrix))
- {
- updatedMatrix[row, col - 1] = 'B';
- }
- if (isInside(row - 1, col + 1, matrix))
- {
- updatedMatrix[row, col + 1] = 'B';
- }
- }
- }
- }
- matrix = updatedMatrix;
- if (!isInside(playerRow, playerCol, matrix))
- {
- printMatrix(matrix);
- Console.WriteLine("won: " + prev);
- return;
- }
- if (matrix[playerRow, playerCol] == 'B')
- {
- printMatrix(matrix);
- Console.WriteLine("dead: " + playerRow + " " + playerCol);
- return;
- }
- }
- }
- private static void printMatrix(char[,] matrix)
- {
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- Console.Write(matrix[row, col]);
- }
- Console.WriteLine();
- }
- }
- private static bool isInside(int row, int col, char[,] matrix)
- {
- return row >= 0 && row < matrix.GetLength(0) && col >= 0 && col < matrix.GetLength(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement