Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Knight_Game
- {
- class Program
- {
- static bool ResultCheck(int maxRow, int maxCol, int row, int col)
- {
- bool result = true;
- result = ((result) && (row >= 0) && (col >= 0));
- result = ((result) && (row < maxRow) && (col < maxCol));
- return result;
- }// bool ResultCheck(int maxRow, int maxCol, int row, int col)
- static bool IsHitKnight(byte[,] board, int row, int col, byte indexJump)
- {
- bool result = false;
- switch (indexJump)
- {
- case 1:
- row -= 1;
- col -= 2;
- break;
- case 2:
- row -= 1;
- col += 2;
- break;
- case 3:
- row += 1;
- col += 2;
- break;
- case 4:
- row += 1;
- col -= 2;
- break;
- case 5:
- row -= 2;
- col -= 1;
- break;
- case 6:
- row -= 2;
- col += 1;
- break;
- case 7:
- row += 2;
- col += 1;
- break;
- case 8:
- row += 2;
- col -= 1;
- break;
- default:
- break;
- }
- result = ResultCheck(board.GetLength(0), board.GetLength(1), row, col);
- if (result)
- {
- result = false;
- if (board[row, col].Equals(1))
- {
- result = true;
- }
- }
- return result;
- }// bool ValidIndex(byte[,] board, int row, int col, byte indexJump)
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- byte[,] board = new byte[n, n];
- for (int row = 0; row < n; row++)
- {
- char[] input = Console.ReadLine().ToCharArray();
- for (int col = 0; col < input.Length; col++)
- {
- switch (input[col].ToString().ToLower())
- {
- case "0":
- board[row, col] = 0;
- break;
- case "k":
- board[row, col] = 1;
- break;
- default:
- break;
- }
- }
- }
- int currentMaxHit = -1;
- int countKnight = 0;
- while (currentMaxHit != 0)
- {
- currentMaxHit = 0;
- int currentMaxHitRow = 0;
- int currentMaxHitCol = 0;
- for (int row = 0; row < board.GetLength(0); row++)
- {
- for (int col = 0; col < board.GetLength(1); col++)
- {
- if (board[row, col].Equals(1))
- {
- int currentHit = 0;
- int currentHitRow = 0;
- int currentHitCol = 0;
- for (byte i = 1; i <= 8; i++)
- {
- if (IsHitKnight(board, row, col, i))
- {
- currentHit++;
- currentHitCol = col;
- currentHitRow = row;
- }
- }
- if (currentHit > currentMaxHit)
- {
- currentMaxHit = currentHit;
- currentMaxHitRow = currentHitRow;
- currentMaxHitCol = currentHitCol;
- }
- }
- }
- }
- if (currentMaxHit != 0)
- {
- board[currentMaxHitRow, currentMaxHitCol] = 0;
- countKnight++;
- }
- }// while (countKnight != 0)
- Console.WriteLine(countKnight);
- }
- }
- }
Advertisement
RAW Paste Data
Copied
Advertisement