Advertisement
Guest User

Untitled

a guest
May 24th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _8._Bombs
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int rows = int.Parse(Console.ReadLine());
  11.  
  12. int[,] matrix = new int[rows, rows];
  13.  
  14. for (int i = 0; i < rows; i++)
  15. {
  16. int[] values = Console.ReadLine()
  17. .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  18. .Select(int.Parse)
  19. .ToArray();
  20.  
  21. for (int j = 0; j < rows; j++)
  22. {
  23. matrix[i, j] = values[j];
  24. }
  25. }
  26.  
  27.  
  28. string[] coordinates = Console.ReadLine()
  29. .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  30. .ToArray();
  31.  
  32.  
  33. for (int i = 0; i < coordinates.Count(); i++)
  34. {
  35. int[] bombCoordinates = coordinates[i]
  36. .Split(",", StringSplitOptions.RemoveEmptyEntries)
  37. .Select(int.Parse)
  38. .ToArray();
  39.  
  40. int bombRow = bombCoordinates[0];
  41. int bombCol = bombCoordinates[1];
  42.  
  43. int bombPower = matrix[bombRow, bombCol];
  44.  
  45. matrix[bombRow, bombCol] = 0;
  46.  
  47. //currentRow = bombRow - 1
  48. if (bombRow - 1 >= 0 && bombCol - 1 >= 0)
  49. {
  50. if (matrix[bombRow - 1, bombCol - 1] > 0)
  51. {
  52. matrix[bombRow - 1, bombCol - 1] -= bombPower;
  53. }
  54. }
  55.  
  56. if (bombRow - 1 >= 0)
  57. {
  58. if (matrix[bombRow - 1, bombCol] > 0)
  59. {
  60. matrix[bombRow - 1, bombCol] -= bombPower;
  61. }
  62. }
  63.  
  64. if (bombRow - 1 >= 0 && bombCol + 1 < rows)
  65. {
  66. if (matrix[bombRow - 1, bombCol + 1] > 0)
  67. {
  68. matrix[bombRow - 1, bombCol + 1] -= bombPower;
  69. }
  70. }
  71.  
  72. //currentRow = bombRow
  73. if (bombCol - 1 >= 0)
  74. {
  75. if (matrix[bombRow, bombCol - 1] > 0)
  76. {
  77. matrix[bombRow, bombCol - 1] -= bombPower;
  78. }
  79. }
  80. if (bombCol + 1 < rows)
  81. {
  82. if (matrix[bombRow, bombCol + 1] > 0)
  83. {
  84. matrix[bombRow, bombCol + 1] -= bombPower;
  85. }
  86. }
  87.  
  88. //currentRow = bombRow + 1
  89. if (bombRow + 1 < rows && bombCol - 1 >= 0)
  90. {
  91. if (matrix[bombRow + 1, bombCol - 1] > 0)
  92. {
  93. matrix[bombRow + 1, bombCol - 1] -= bombPower;
  94. }
  95. }
  96. if (bombRow + 1 < rows)
  97. {
  98. if (matrix[bombRow + 1, bombCol] > 0)
  99. {
  100. matrix[bombRow + 1, bombCol] -= bombPower;
  101. }
  102. }
  103. if (bombRow + 1 < rows && bombCol + 1 < rows)
  104. {
  105. if (matrix[bombRow + 1, bombCol + 1] > 0)
  106. {
  107. matrix[bombRow + 1, bombCol + 1] -= bombPower;
  108. }
  109. }
  110. }
  111.  
  112. //CHECK IF THERE ARE ALIVE CELLS
  113. int counter = 0;
  114. int sum = 0;
  115.  
  116. for (int i = 0; i < rows; i++)
  117. {
  118. for (int j = 0; j < rows; j++)
  119. {
  120. if (matrix[i, j] > 0)
  121. {
  122. counter++;
  123. sum += matrix[i, j];
  124. }
  125. }
  126. }
  127.  
  128. //OUTPUT
  129. Console.WriteLine($"Alive cells: {counter}");
  130. Console.WriteLine($"Sum: {sum}");
  131.  
  132. for (int i = 0; i < rows; i++)
  133. {
  134. for (int j = 0; j < rows; j++)
  135. {
  136. Console.Write($"{matrix[i, j]} ");
  137. }
  138. Console.WriteLine();
  139. }
  140. }
  141. }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement