Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace Knight_Game
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- char[][] matrix = new char[n][];
- for (int row = 0; row < n; row++)
- {
- matrix[row] = Console.ReadLine().ToLower().ToCharArray(); // Тук
- }
- int removeKnight = 0;
- while (true)
- {
- int knightRow = -1; //za da zapocha izvyn igrishteto
- int knightCol = -1;
- int maxAtacked = 0;
- for (int row = 0; row < n; row++)
- {
- for (int col = 0; col < n; col++)
- {
- if (matrix[row][col] == 'k')
- {
- int tempAtack = CountAtacks(matrix, row, col);
- if (tempAtack > maxAtacked)
- {
- maxAtacked = tempAtack;
- knightRow = row;
- knightCol = col;
- }
- }
- }
- }
- if (maxAtacked > 0)
- {
- matrix[knightRow][knightCol] = '0';
- removeKnight++;
- }
- else
- {
- break;
- }
- }
- Console.WriteLine(removeKnight);
- }
- static int CountAtacks(char[][] matrix, int row, int col)
- {
- int atacks = 0; //колко атаки ще направя
- if (IsExist(row + 1, col - 2, matrix.Length) && matrix[row + 1][col - 2] == 'k')
- {
- atacks++;
- }
- if (IsExist(row - 1, col - 2, matrix.Length) && matrix[row - 1][col - 2] == 'k')
- {
- atacks++;
- }
- if (IsExist(row - 1, col + 2, matrix.Length) && matrix[row - 1][col + 2] == 'k')
- {
- atacks++;
- }
- if (IsExist(row + 1, col + 2, matrix.Length) && matrix[row + 1][col + 2] == 'k')
- {
- atacks++;
- }
- if (IsExist(row - 2, col - 1, matrix.Length) && matrix[row - 2][col - 1] == 'k')
- {
- atacks++;
- }
- if (IsExist(row - 2, col + 1, matrix.Length) && matrix[row - 2][col + 1] == 'k')
- {
- atacks++;
- }
- if (IsExist(row + 2, col - 1, matrix.Length) && matrix[row + 2][col - 1] == 'k')
- {
- atacks++;
- }
- if (IsExist(row + 2, col + 1, matrix.Length) && matrix[row + 2][col + 1] == 'k')
- {
- atacks++;
- }
- return atacks;
- }
- private static bool IsExist(int row, int col, int lenght)
- {
- return row >= 0 && row < lenght && col >= 0 && col < lenght; ///проверка дали е в полето
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement