Advertisement
Guest User

Untitled

a guest
May 21st, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace E08._Bombs
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int size = int.Parse(Console.ReadLine());
  11.  
  12. int rows = size;
  13. int cols = size;
  14.  
  15. int[,] matrix = new int[rows, cols];
  16.  
  17. for (int i = 0; i < matrix.GetLength(0); i++)
  18. {
  19. int[] numbers = Console.ReadLine()
  20. .Split()
  21. .Select(int.Parse)
  22. .ToArray();
  23. for (int j = 0; j < matrix.GetLength(1); j++)
  24. {
  25. matrix[i, j] += numbers[j];
  26. }
  27. }
  28.  
  29. string[] coordinates = Console.ReadLine()
  30. .Split()
  31. .ToArray();
  32.  
  33. for (int i = 0; i < coordinates.Length; i++)
  34. {
  35. string[] tokens = coordinates[i].Split(",");
  36.  
  37. int currentRow = int.Parse(tokens[0]);
  38. int currentCol = int.Parse(tokens[1]);
  39.  
  40. int currentBomb = matrix[currentRow, currentCol];
  41.  
  42.  
  43. for (int row = 0; row < matrix.GetLength(0); row++)
  44. {
  45. for (int col = 0; col < matrix.GetLength(1); col++)
  46. {
  47. if (currentRow == row && currentCol == col)
  48. {
  49. if (row - 1 >= 0 && row - 1 < matrix.GetLength(0) && col - 1 >= 0 && col - 1 < matrix.GetLength(1)
  50. && matrix[row - 1, col - 1] > 0)
  51. {
  52. matrix[row - 1, col - 1] -= currentBomb;
  53. }
  54. if (row - 1 >= 0 && row - 1 < matrix.GetLength(0)
  55. && matrix[row - 1, col] > 0)
  56. {
  57. matrix[row - 1, col] -= currentBomb;
  58. }
  59. if (row - 1 >= 0 && row - 1 < matrix.GetLength(0) && col + 1 >= 0 && col + 1 < matrix.GetLength(1)
  60. && matrix[row - 1, col + 1] > 0)
  61. {
  62. matrix[row - 1, col + 1] -= currentBomb;
  63. }
  64. if (col - 1 >= 0 && col - 1 < matrix.GetLength(1)
  65. && matrix[row, col - 1] > 0)
  66. {
  67. matrix[row, col - 1] -= currentBomb;
  68. }
  69. if (col + 1 >= 0 && col + 1 < matrix.GetLength(1)
  70. && matrix[row, col + 1] > 0)
  71. {
  72. matrix[row, col + 1] -= currentBomb;
  73. }
  74. if (row + 1 >= 0 && row + 1 < matrix.GetLength(0) && col - 1 >= 0 && col - 1 < matrix.GetLength(1)
  75. && matrix[row + 1, col - 1] > 0)
  76. {
  77. matrix[row + 1, col - 1] -= currentBomb;
  78. }
  79. if (row + 1 >= 0 && row + 1 < matrix.GetLength(0)
  80. && matrix[row + 1, col] > 0)
  81. {
  82. matrix[row + 1, col] -= currentBomb;
  83. }
  84. if (row + 1 >= 0 && row + 1 < matrix.GetLength(0) && col + 1 >= 0 && col + 1 < matrix.GetLength(1)
  85. && matrix[row + 1, col + 1] > 0)
  86. {
  87. matrix[row + 1, col + 1] -= currentBomb;
  88. }
  89. }
  90. }
  91. }
  92. matrix[currentRow, currentCol] = 0;
  93. }
  94. int count = 0;
  95. int sum = 0;
  96.  
  97. for (int row = 0; row < matrix.GetLength(0); row++)
  98. {
  99. for (int col = 0; col < matrix.GetLength(1); col++)
  100. {
  101. if (matrix[row, col] > 0)
  102. {
  103. count++;
  104. sum += matrix[row, col];
  105. }
  106. }
  107. }
  108. Console.WriteLine($"Alive cells: {count}");
  109. Console.WriteLine($"Sum: {sum}");
  110.  
  111. for (int row = 0; row < matrix.GetLength(0); row++)
  112. {
  113. for (int col = 0; col < matrix.GetLength(1); col++)
  114. {
  115. Console.Write(matrix[row, col] + " ");
  116. }
  117. Console.WriteLine();
  118. }
  119. }
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement