Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace SampleExamP03
- {
- class Program
- {
- static void Main()
- {
- int rows = int.Parse(Console.ReadLine());
- char[][] jagged = new char[rows][];
- for (int row = 0; row < rows; row++)
- {
- string input = Console.ReadLine();
- jagged[row] = new char[input.Length];
- for (int col = 0; col < rows; col++)
- {
- jagged[row][col] = input[col];
- }
- }
- int removedHorses = 0;
- while (true)
- {
- int knightRow = -1;
- int knightCol = -1;
- int maxAttacked = 0;
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < rows; col++)
- {
- if (jagged[row][ col] == 'K')
- {
- int tempAttack = CountAttacks(jagged, row, col);
- if (tempAttack > maxAttacked)
- {
- maxAttacked = tempAttack;
- knightRow = row;
- knightCol = col;
- }
- }
- }
- }
- if (maxAttacked > 0)
- {
- jagged[knightRow][ knightCol] = '0';
- removedHorses++;
- }
- else
- {
- break;
- }
- }
- Console.WriteLine(removedHorses);
- }
- private static int CountAttacks(char[][] jagged, int row, int col)
- {
- int attacks = 0;
- if (isInJagged(row - 1, col - 2, jagged.Length) && jagged[row - 1][ col - 2] == 'K')
- {
- attacks++;
- }
- if (isInJagged(row - 1, col + 2, jagged.Length) && jagged[row - 1][col + 2] == 'K')
- {
- attacks++;
- }
- if (isInJagged(row + 1, col - 2, jagged.Length) && jagged[row + 1][col - 2] == 'K')
- {
- attacks++;
- }
- if (isInJagged(row + 1, col + 2, jagged.Length) && jagged[row + 1][col + 2] == 'K')
- {
- attacks++;
- }
- if (isInJagged(row - 2, col - 1, jagged.Length) && jagged[row - 2][col - 1] == 'K')
- {
- attacks++;
- }
- if (isInJagged(row - 2, col + 1, jagged.Length) && jagged[row - 2][col + 1] == 'K')
- {
- attacks++;
- }
- if (isInJagged(row + 2, col - 1, jagged.Length) && jagged[row + 2][col - 1] == 'K')
- {
- attacks++;
- }
- if (isInJagged(row + 2, col + 1, jagged.Length) && jagged[row + 2][col + 1] == 'K')
- {
- attacks++;
- }
- return attacks;
- }
- private static bool isInJagged(int row, int col, int length)
- {
- return row >= 0 && row < length && col >= 0 && col < length;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment