Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. using System;
  2.  
  3. namespace KnightGame
  4. {
  5. public class KnightGame
  6. {
  7. static bool isValidIndex(int index1, int index2, int size)
  8. {
  9. return index1 >= 0 && index2 >= 0 && index1 < size && index2 < size;
  10. }
  11. public static void Main()
  12. {
  13. int N = int.Parse(Console.ReadLine());
  14. char[,] table = new char[N, N];
  15. for (int i = 0; i < N; i++)
  16. {
  17. var row = Console.ReadLine().ToCharArray();
  18. for (int j = 0; j < N; j++)
  19. {
  20. table[i, j] = row[j];
  21. }// input;
  22. }
  23. int counter = 0;
  24. int maxDanagerous = -1;
  25. int maxDanagerousRow = 0;
  26. int maxDanagerousCol = 0;
  27. int cuurentDangareous = 0;
  28. while (true)
  29. {
  30. for (int i = 0; i < N; i++)
  31. {
  32. for (int j = 0; j < N; j++)
  33. {
  34. cuurentDangareous = 0;
  35. if (table[i, j] == 'K')
  36. {
  37. if (isValidIndex(i - 2, j + 1, N))
  38. {
  39. if (table[i - 2, j + 1] == 'K')
  40. {
  41. cuurentDangareous++;
  42. }
  43. }
  44.  
  45. if (isValidIndex(i - 1, j + 2, N))
  46. {
  47. if (table[i - 1, j + 2] == 'K')
  48. {
  49. cuurentDangareous++;
  50. }
  51. }
  52.  
  53. if (isValidIndex(i + 1, j + 2, N))
  54. {
  55. if (table[i + 1, j + 2] == 'K')
  56. {
  57. cuurentDangareous++;
  58. }
  59. }
  60.  
  61. if (isValidIndex(i + 2, j + 1, N))
  62. {
  63. if (table[i + 2, j + 1] == 'K')
  64. {
  65. cuurentDangareous++;
  66. }
  67. }
  68.  
  69. if (isValidIndex(i + 2, j - 1, N))
  70. {
  71. if (table[i + 2, j - 1] == 'K')
  72. {
  73. cuurentDangareous++;
  74. }
  75. }
  76.  
  77. if (isValidIndex(i + 1, j - 2, N))
  78. {
  79. if (table[i + 1, j - 2] == 'K')
  80. {
  81. cuurentDangareous++;
  82. }
  83. }
  84.  
  85. if (isValidIndex(i - 1, j - 2, N))
  86. {
  87. if (table[i - 1, j - 2] == 'K')
  88. {
  89. cuurentDangareous++;
  90. }
  91. }
  92.  
  93. if (isValidIndex(i - 2, j - 1, N))
  94. {
  95. if (table[i - 2, j - 1] == 'K')
  96. {
  97. cuurentDangareous++;
  98. }
  99. }
  100. if (cuurentDangareous > maxDanagerous)
  101. {
  102. maxDanagerous = cuurentDangareous;
  103. maxDanagerousRow = i;
  104. maxDanagerousCol = j;
  105. }
  106. }
  107. }
  108. }
  109. if (maxDanagerous == 0)
  110. {
  111. Console.WriteLine(counter);
  112. return;
  113. }
  114. else
  115. {
  116. table[maxDanagerousRow, maxDanagerousCol] = '0';
  117. maxDanagerous = 0;
  118. counter++;
  119. }
  120. }
  121. }
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement