Guest User

Untitled

a guest
May 22nd, 2019
78
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace arrays
  8. {
  9. class Program
  10. {
  11.  
  12. static void Main(string[] args)
  13. {
  14. int fieldSize = int.Parse(Console.ReadLine());
  15. var field = new char[fieldSize, fieldSize];
  16. int horseAttacks = 0;
  17. int removed = 0;
  18. for (int row = 0; row < fieldSize; row++)
  19. {
  20. string sentence = Console.ReadLine();
  21. for (int col = 0; col < fieldSize; col++)
  22. {
  23. field[row, col] = sentence[col];
  24. }
  25. }
  26. int[] attacks = new int[] { 1, 2, 1, -2, -1, 2, -1, -2, 2, 1, 2, -1, -2, 1, -2, -1 };
  27. while (true)
  28. {
  29. int bestattacks = 0;
  30. int bestcol = 0;
  31. int bestrow = 0;
  32. for (int row = 0; row < fieldSize; row++)
  33. {
  34. for (int col = 0; col < fieldSize; col++)
  35. {
  36. int currentHorse = 0;
  37. if (field[row, col] == 'K')
  38. {
  39. for (int i = 0; i < attacks.Length; i+=2)
  40. {
  41. if (Isinside(field, row + attacks[i], col + attacks[i + 1])
  42. && field[row + attacks[i], col + attacks[i + 1]] == 'K')
  43. {
  44. currentHorse++;
  45. }
  46. }
  47.  
  48. }
  49. if (currentHorse > bestattacks)
  50. {
  51. bestattacks = currentHorse;
  52. bestcol = col;
  53. bestrow = row;
  54. }
  55.  
  56. }
  57. }
  58. if (bestattacks == 0)
  59. {
  60. break;
  61. }
  62. field[bestcol, bestrow] = '0';
  63. removed++;
  64. }
  65. Console.WriteLine(removed);
  66.  
  67. }
  68.  
  69. private static bool Isinside(char[,] field, int desiredRow, int desiredCol)
  70. {
  71. return desiredRow >= 0 && desiredRow < field.GetLength(0) && desiredCol >= 0 && desiredCol < field.GetLength(1);
  72.  
  73. }
  74. }
  75. }
RAW Paste Data