Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Sneaking
- {
- class Program
- {
- static void Main(string[] args)
- {
- int rows = int.Parse(Console.ReadLine());
- int nikoladzeRow = -1;
- int nikoladzeCol = -1;
- int currentRow = -1;
- int currentCol = -1;
- char[] cols = Console.ReadLine().ToCharArray();
- char[,] matrix = new char[rows,cols.Length];
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < cols.Length; col++)
- {
- matrix[row, col] = cols[col];
- if (matrix[row, col] == 'N')
- {
- nikoladzeRow = row;
- nikoladzeCol = col;
- }
- else if (matrix[row, col] == 'S')
- {
- currentRow = row;
- currentCol = col;
- }
- }
- if(row<rows-1)
- {
- cols = Console.ReadLine().ToCharArray();
- }
- }
- char[] commands = Console.ReadLine().ToCharArray();
- for (int i = 0; i < commands.Length; i++)
- {
- char command = (char)commands[i];
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- if (matrix[row, col] == 'b')
- {
- if (col == matrix.GetLength(1) - 1)
- {
- matrix[row, col] = 'd';
- }
- else if (col < matrix.GetLength(1) - 1)
- {
- matrix[row, col] = '.';
- matrix[row, col + 1] = 'b';
- }
- if (currentRow == row && currentCol > col)
- {
- Console.WriteLine($"Sam died at {row}, {col}");
- matrix[row, col] = 'X';
- return;
- }
- }
- else if (matrix[row, col] == 'd')
- {
- if (col == 0)
- {
- matrix[row, col] = 'b';
- }
- else if (col > 0)
- {
- matrix[row, col] = '.';
- matrix[row, col - 1] = 'd';
- }
- if (currentRow == row && currentCol < col)
- {
- Console.WriteLine($"Sam died at {row}, {col}");
- matrix[row, col] = 'X';
- return;
- }
- }
- }
- }
- if (command == 'U')
- {
- if (matrix[currentRow - 1, currentCol] == 'b' || matrix[currentRow - 1, currentCol] == 'd')
- {
- matrix[currentRow, currentCol] = '.';
- matrix[currentRow - 1, currentCol] = 'S';
- currentRow = currentRow - 1;
- }
- else
- {
- matrix[currentRow, currentCol] = '.';
- matrix[currentRow - 1, currentCol] = 'S';
- currentRow = currentRow - 1;
- }
- if (currentRow == nikoladzeRow)
- {
- Console.WriteLine($"Nikoladze killed!");
- matrix[nikoladzeRow, nikoladzeCol] = 'X';
- return;
- }
- }
- if (command == 'D')
- {
- if (matrix[currentRow + 1, currentCol] == 'b' || matrix[currentRow + 1, currentCol] == 'd')
- {
- matrix[currentRow, currentCol] = '.';
- matrix[currentRow + 1, currentCol] = 'S';
- currentRow = currentRow + 1;
- }
- else
- {
- matrix[currentRow, currentCol] = '.';
- matrix[currentRow + 1, currentCol] = 'S';
- currentRow = currentRow + 1;
- }
- if (currentRow == nikoladzeRow)
- {
- Console.WriteLine($"Nikoladze killed!");
- matrix[nikoladzeRow, nikoladzeCol] = 'X';
- return;
- }
- }
- if (command == 'L')
- {
- if (matrix[currentRow, currentCol - 1] == 'b' || matrix[currentRow, currentCol - 1] == 'd')
- {
- matrix[currentRow, currentCol] = '.';
- matrix[currentRow, currentCol - 1] = 'S';
- currentCol = currentCol - 1;
- }
- else
- {
- matrix[currentRow, currentCol] = '.';
- matrix[currentRow, currentCol - 1] = 'S';
- currentCol = currentCol - 1;
- }
- }
- if (command == 'R')
- {
- if (matrix[currentRow, currentCol + 1] == 'b' || matrix[currentRow, currentCol + 1] == 'd')
- {
- matrix[currentRow, currentCol] = '.';
- matrix[currentRow, currentCol + 1] = 'S';
- currentCol = currentCol + 1;
- }
- else
- {
- matrix[currentRow, currentCol] = '.';
- matrix[currentRow, currentCol + 1] = 'S';
- currentCol = currentCol + 1;
- }
- }
- }
- 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();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement