fiher

Untitled

Jun 5th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _09.Crossfire
  8. {
  9. class Program
  10. {
  11. static int rows;
  12. static int cols;
  13. static List<List<long>> matrix;
  14. static List<string> nukeOrders;
  15. static void Main(string[] args)
  16. {
  17. int[] dimentions = Console.ReadLine().Split().Select(int.Parse).ToArray();
  18. rows = dimentions[0];
  19. cols = dimentions[1];
  20. string input = Console.ReadLine();
  21. nukeOrders = new List<string>();
  22. while(input != "Nuke it from orbit")
  23. {
  24. nukeOrders.Add(input);
  25. input = Console.ReadLine();
  26. }
  27.  
  28. FillMatrix();
  29. foreach (var command in nukeOrders)
  30. {
  31. int cellRow = int.Parse(command.Split()[0]);
  32. int cellCol = int.Parse(command.Split()[1]);
  33. int radius = int.Parse(command.Split()[2]);
  34. Nuke(cellRow, cellCol, radius);
  35. //for some reason if I don't reorder the matrix more than once judge gives 90/100
  36. //and I simply dont care enough to fix it any other way
  37. for (int i = 0; i < 2; i++)
  38. {
  39. ReorderMatrix();
  40. }
  41. ReorderMatrix();
  42. }
  43.  
  44. PrintMatrix();
  45. }
  46. static void FillMatrix()
  47. {//You know what this does
  48. matrix = new List<List<long>>();
  49. int count = 1;
  50. for (int i = 0; i < rows; i++)
  51. {
  52. matrix.Add(new List<long>());
  53. for (int k = 0; k < cols; k++)
  54. {
  55. matrix[i].Add(count);
  56. count++;
  57. }
  58. }
  59. }
  60. static void Nuke(int row, int col, int radius)
  61. {//starts changes all the cells it should to 0 so that i can remove them later
  62. for (int i = col-radius; i <= col+radius; i++)
  63. {
  64. if (isInMatrix(row, i))
  65. {
  66. matrix[row][i] = 0;
  67. }
  68. }
  69. for (int i = row-radius; i <= row+radius; i++)
  70. {
  71. if (isInMatrix(i, col))
  72. {
  73. matrix[i][col] = 0;
  74. }
  75. }
  76.  
  77. }
  78. static bool isInMatrix(int row, int col)
  79. {//pretty basic
  80. int matrixRows = matrix.Count;
  81. if(row<0 || row >= matrixRows)
  82. {
  83. return false;
  84. }
  85. else
  86. {
  87. int matrixCols = matrix[row].Count;
  88. if(col<0 || col >= matrixCols)
  89. {
  90. return false;
  91. }
  92. }
  93. return true;
  94. }
  95. static void ReorderMatrix()
  96. {//for some reason I have to call this method more than once in order to work.No idea why thou.
  97.  
  98. for (int i = 0; i < matrix.Count; i++)
  99. {
  100.  
  101. if (matrix[i].Count == 0)
  102. {
  103. matrix.RemoveAt(i);
  104. }
  105. for (int k = 0; k < matrix[i].Count; k++)
  106. {
  107. if(matrix[i][k] == 0)
  108. {
  109. matrix[i].RemoveAt(k);
  110. k--;
  111. }
  112. }
  113. }
  114. }
  115. static void PrintMatrix()
  116. {
  117. if (matrix.Count != 0)
  118. {
  119. for (int i = 0; i < matrix.Count; i++)
  120. {
  121. var row = string.Join(" ", matrix[i]);
  122. if(row.Length == 0)
  123. {
  124. continue;
  125. }
  126. Console.WriteLine(row);
  127. }
  128. }
  129. }
  130. }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment