Advertisement
Guest User

Untitled

a guest
May 21st, 2016
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5.  
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int[] array = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  11.  
  12. List<int[]> matrix = new List<int[]>();
  13. int counter = 1;
  14. for (int i = 0; i < array[0]; i++)
  15. {
  16. matrix.Add(new int[array[1]]);
  17. for (int j = 0; j < array[1]; j++)
  18. {
  19. matrix[i][j] = counter++;
  20. }
  21. }
  22. string input = Console.ReadLine();
  23.  
  24. while (input != "Nuke it from orbit")
  25. {
  26. int[] coords = input.Split(' ').Select(int.Parse).ToArray();
  27.  
  28. int row = coords[0];
  29. int col = coords[1];
  30. int radius = coords[2];
  31.  
  32. Nuke(row, col, radius, matrix);
  33.  
  34.  
  35.  
  36. input = Console.ReadLine();
  37. }
  38.  
  39.  
  40. for (int i = 0; i < matrix.Count; i++)
  41. {
  42. Console.WriteLine(string.Join(" ", matrix[i]));
  43. }
  44. }
  45.  
  46. private static void Nuke(int r, int c, int radius, List<int[]> matrix)
  47. {
  48. for (int row = r - radius; row <= r + radius; row++)
  49. {
  50. if (row >= 0 && row < matrix.Count)
  51. {
  52. if (c >= 0 && c < matrix[row].Length)
  53. {
  54. matrix[row][c] = 0;
  55. }
  56. }
  57. }
  58.  
  59. for (int col = c - radius; col <= c + radius; col++)
  60. {
  61. if (r < 0 ^ r >= matrix.Count)
  62. {
  63. continue;
  64. }
  65. if (col >= 0 && col < matrix[r].Length)
  66. {
  67. matrix[r][col] = 0;
  68. }
  69. }
  70. for (int i = 0; i < matrix.Count; i++)
  71. {
  72. List<int> numbers = matrix[i].ToList();
  73. numbers.RemoveAll(a => a == 0);
  74. if (numbers.Count != 0)
  75. {
  76. matrix[i] = numbers.ToArray();
  77. }
  78. else
  79. {
  80. matrix.RemoveAt(i);
  81. }
  82. }
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement