Advertisement
Guest User

Untitled

a guest
May 21st, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. namespace _07._Knight_Game
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int dimensions = int.Parse(Console.ReadLine());
  10.  
  11. char[,] board = new char[dimensions, dimensions];
  12.  
  13. for (int row = 0; row < board.GetLength(0); row++)
  14. {
  15. string elementsOfMatrix = Console.ReadLine();
  16.  
  17. for (int col = 0; col < board.GetLength(1); col++)
  18. {
  19. board[row, col] = elementsOfMatrix[col];
  20. }
  21. }
  22. //end of insertion;
  23.  
  24. int removedHorses = 0;
  25.  
  26. for (int row = 0; row < board.GetLength(0); row++)
  27. {
  28. for (int col = 0; col < board.GetLength(1); col++)
  29. {
  30. if (board[row, col] == 'K')
  31. {
  32. if (row - 2 < board.GetLength(0) && col - 1 < board.GetLength(1)&&row-2>=0&&col-2>=0
  33. && board[row - 2, col - 1] == 'K')
  34. {
  35. removedHorses++;
  36. board[row, col] = '0';
  37. }
  38. if (row - 2 < board.GetLength(0) && col +1 < board.GetLength(1) && row - 2 >= 0 && col +1 >= 0
  39. && board[row - 2, col +1] == 'K')
  40. {
  41. removedHorses++;
  42. board[row, col] = '0';
  43. }
  44. if (row - 1 < board.GetLength(0) && col +2 < board.GetLength(1) && row - 1 >= 0 && col + 2 >= 0
  45. && board[row - 1, col +2] == 'K')
  46. {
  47. removedHorses++;
  48. board[row, col] = '0';
  49. }
  50. if (row +1 < board.GetLength(0) && col +2 < board.GetLength(1) && row +1 >= 0 && col +2 >= 0
  51. && board[row +1, col +2] == 'K')
  52. {
  53. removedHorses++;
  54. board[row, col] = '0';
  55. }
  56. //4 completed
  57.  
  58. if (row + 2 < board.GetLength(0) && col + 1 < board.GetLength(1) && row + 2 >= 0 && col +1 >= 0
  59. && board[row +2, col +1] == 'K')
  60. {
  61. removedHorses++;
  62. board[row, col] = '0';
  63. }
  64. if (row +2 < board.GetLength(0) && col - 1 < board.GetLength(1) && row + 2 >= 0 && col -1 >= 0
  65. && board[row + 2, col - 1] == 'K')
  66. {
  67. removedHorses++;
  68. board[row, col] = '0';
  69. }
  70. if (row +1 < board.GetLength(0) && col - 2 < board.GetLength(1) && row + 1 >= 0 && col - 2 >= 0
  71. && board[row +1, col - 2] == 'K')
  72. {
  73. removedHorses++;
  74. board[row, col] = '0';
  75. }
  76. if (row - 1 < board.GetLength(0) && col - 2 < board.GetLength(1) && row - 1 >= 0 && col - 2 >= 0
  77. && board[row - 1, col - 2] == 'K')
  78. {
  79. removedHorses++;
  80. board[row, col] = '0';
  81. }
  82. }
  83. }
  84. }
  85. Console.WriteLine(removedHorses);
  86. }
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement