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 4.50 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) && matrix[row - 1, col - 1] > 0)
  50. {
  51. matrix[row - 1, col - 1] -= currentBomb;
  52. }
  53. if (row - 1 >= 0 && row - 1 < matrix.GetLength(0) && matrix[row - 1, col] > 0)
  54. {
  55. matrix[row - 1, col] -= currentBomb;
  56.  
  57. }
  58. if (row - 1 >= 0 && row - 1 < matrix.GetLength(0) && col + 1 >= 0 && col + 1 < matrix.GetLength(1) && matrix[row - 1, col + 1] > 0)
  59. {
  60.  
  61. matrix[row - 1, col + 1] -= currentBomb;
  62.  
  63. }
  64. if (col - 1 >= 0 && col - 1 < matrix.GetLength(1) && matrix[row, col - 1] > 0)
  65. {
  66. matrix[row, col - 1] -= currentBomb;
  67.  
  68. }
  69. if (col + 1 >= 0 && col + 1 < matrix.GetLength(1) && matrix[row, col + 1] > 0)
  70. {
  71.  
  72. matrix[row, col + 1] -= currentBomb;
  73.  
  74. }
  75. if (row + 1 >= 0 && row + 1 < matrix.GetLength(0) && col - 1 >= 0 && col - 1 < matrix.GetLength(1) && matrix[row + 1, col - 1] > 0)
  76. {
  77.  
  78. matrix[row + 1, col - 1] -= currentBomb;
  79.  
  80. }
  81. if (row + 1 >= 0 && row + 1 < matrix.GetLength(0) && matrix[row + 1, col] > 0)
  82. {
  83. matrix[row + 1, col] -= currentBomb;
  84.  
  85.  
  86. }
  87. if (row + 1 >= 0 && row + 1 < matrix.GetLength(0) && col + 1 >= 0 && col + 1 < matrix.GetLength(1) && matrix[row + 1, col + 1] > 0)
  88. {
  89. matrix[row + 1, col + 1] -= currentBomb;
  90.  
  91. }
  92.  
  93. }
  94. }
  95.  
  96. }
  97. matrix[currentRow, currentCol] = 0;
  98. }
  99. int count = 0;
  100. int sum = 0;
  101.  
  102. for (int row = 0; row < matrix.GetLength(0); row++)
  103. {
  104. for (int col = 0; col < matrix.GetLength(1); col++)
  105. {
  106. if (matrix[row, col] > 0)
  107. {
  108. count++;
  109. sum += matrix[row, col];
  110. }
  111. }
  112. }
  113. Console.WriteLine($"Alive cells: {count}");
  114. Console.WriteLine($"Sum: {sum}");
  115.  
  116. for (int row = 0; row < matrix.GetLength(0); row++)
  117. {
  118. for (int col = 0; col < matrix.GetLength(1); col++)
  119. {
  120. Console.Write(matrix[row, col] + " ");
  121. }
  122. Console.WriteLine();
  123. }
  124. }
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement