Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _07.KnightGame
- {
- class Program
- {
- static void Main(string[] args)
- {
- int size = int.Parse(Console.ReadLine());
- char[,] matrix = new char[size, size];
- for (int row = 0; row < size; row++)
- {
- char[] input = Console.ReadLine().ToCharArray();
- for (int col = 0; col < size; col++)
- {
- matrix[row, col] = input[col];
- }
- }
- int maxAttacks = 0;
- int KillerRow = 0;
- int KillerCol = 0;
- int removedKnights = 0;
- while (true)
- {
- for (int row = 0; row < size; row++)
- {
- for (int col = 0; col < size; col++)
- {
- int currentAttacks = 0;
- if (matrix[row, col] == 'K')
- {
- //arr[row+1,col+2]
- if (Inside(matrix, row+1, col+2) && matrix[row + 1, col + 2] == 'K')
- {
- currentAttacks++;
- }
- //arr[row+1,col-2]
- if (Inside(matrix, row+1, col-2) && matrix[row + 1, col - 2] == 'K')
- {
- currentAttacks++;
- }
- //arr[row+2,col+1]
- if (Inside(matrix, row+2, col+1) && matrix[row + 2, col + 1] == 'K')
- {
- currentAttacks++;
- }
- //arr[row+2,col-1]
- if (Inside(matrix, row+2, col-1) && matrix[row + 2, col - 1] == 'K')
- {
- currentAttacks++;
- }
- //arr[row-2,col-1]
- if (Inside(matrix, row-2, col-1) && matrix[row - 2, col - 1] == 'K')
- {
- currentAttacks++;
- }
- //arr[row-1,col-2]
- if (Inside(matrix, row-1, col-2) && matrix[row - 1, col - 2] == 'K')
- {
- currentAttacks++;
- }
- //arr[row-1,col+2]
- if (Inside(matrix, row-1, col+2) && matrix[row - 1, col + 2] == 'K')
- {
- currentAttacks++;
- }
- //arr[row-2,col+1]
- if (Inside(matrix, row-2, col+1) && matrix[row - 2, col + 1] == 'K')
- {
- currentAttacks++;
- }
- }
- if (currentAttacks > maxAttacks)
- {
- maxAttacks = currentAttacks;
- KillerRow = row;
- KillerCol = col;
- }
- }
- }
- // ако имаме кон, който атакува, трябва да го премахнем и задължително зануляваме maxAttacsa!!!
- if (maxAttacks > 0)
- {
- matrix[KillerRow, KillerCol] = '0';
- removedKnights++;
- maxAttacks = 0;
- }
- else
- {
- Console.WriteLine(removedKnights);
- break;
- }
- }
- }
- private static bool Inside(char[,] matrix, int row, int col)
- {
- return row >= 0 && row < matrix.GetLength(0) && col >= 0 && col < matrix.GetLength(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement