Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _07._Knight_Game
- {
- class Program
- {
- static void Main(string[] args)
- {
- int dimensions = int.Parse(Console.ReadLine());
- char[,] board = new char[dimensions, dimensions];
- for (int row = 0; row < board.GetLength(0); row++)
- {
- string elementsOfMatrix = Console.ReadLine();
- for (int col = 0; col < board.GetLength(1); col++)
- {
- board[row, col] = elementsOfMatrix[col];
- }
- }
- //end of insertion;
- int removedHorses = 0;
- for (int row = 0; row < board.GetLength(0); row++)
- {
- for (int col = 0; col < board.GetLength(1); col++)
- {
- if (board[row, col] == 'K')
- {
- if (row - 2 < board.GetLength(0) && col - 1 < board.GetLength(1)&&row-2>=0&&col-2>=0
- && board[row - 2, col - 1] == 'K')
- {
- removedHorses++;
- board[row, col] = '0';
- }
- if (row - 2 < board.GetLength(0) && col +1 < board.GetLength(1) && row - 2 >= 0 && col +1 >= 0
- && board[row - 2, col +1] == 'K')
- {
- removedHorses++;
- board[row, col] = '0';
- }
- if (row - 1 < board.GetLength(0) && col +2 < board.GetLength(1) && row - 1 >= 0 && col + 2 >= 0
- && board[row - 1, col +2] == 'K')
- {
- removedHorses++;
- board[row, col] = '0';
- }
- if (row +1 < board.GetLength(0) && col +2 < board.GetLength(1) && row +1 >= 0 && col +2 >= 0
- && board[row +1, col +2] == 'K')
- {
- removedHorses++;
- board[row, col] = '0';
- }
- //4 completed
- if (row + 2 < board.GetLength(0) && col + 1 < board.GetLength(1) && row + 2 >= 0 && col +1 >= 0
- && board[row +2, col +1] == 'K')
- {
- removedHorses++;
- board[row, col] = '0';
- }
- if (row +2 < board.GetLength(0) && col - 1 < board.GetLength(1) && row + 2 >= 0 && col -1 >= 0
- && board[row + 2, col - 1] == 'K')
- {
- removedHorses++;
- board[row, col] = '0';
- }
- if (row +1 < board.GetLength(0) && col - 2 < board.GetLength(1) && row + 1 >= 0 && col - 2 >= 0
- && board[row +1, col - 2] == 'K')
- {
- removedHorses++;
- board[row, col] = '0';
- }
- if (row - 1 < board.GetLength(0) && col - 2 < board.GetLength(1) && row - 1 >= 0 && col - 2 >= 0
- && board[row - 1, col - 2] == 'K')
- {
- removedHorses++;
- board[row, col] = '0';
- }
- }
- }
- }
- Console.WriteLine(removedHorses);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement