Advertisement
dobroslav-atanasov

Untitled

Jan 30th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. namespace _06._TargetPractice
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7.  
  8. public class Program
  9. {
  10. public static void Main()
  11. {
  12. var sizes = Console.ReadLine()
  13. .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  14. .Select(int.Parse)
  15. .ToArray();
  16.  
  17. var rows = sizes[0];
  18. var cols = sizes[1];
  19. var matrix = new char[rows, cols];
  20.  
  21. var inputString = Console.ReadLine();
  22. var queue = new Queue<char>(inputString);
  23.  
  24. var shotParameters = Console.ReadLine()
  25. .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  26. .Select(int.Parse)
  27. .ToArray();
  28.  
  29. var impactRow = shotParameters[0];
  30. var impactCol = shotParameters[1];
  31. var radius = shotParameters[2];
  32.  
  33. FillMatrix(matrix, inputString);
  34.  
  35. FireAShot(matrix, impactRow, impactCol, radius);
  36.  
  37. RunGravity(matrix);
  38.  
  39. PrintMatrix(matrix);
  40. }
  41.  
  42. private static void FillMatrix(char[,] matrix, string inputString)
  43. {
  44. int index = 0;
  45. int numberOfRows = 0;
  46. for (int row = matrix.GetLength(0) - 1; row >= 0; row--)
  47. {
  48. if (numberOfRows % 2 == 0)
  49. {
  50. for (int col = matrix.GetLength(1) - 1; col >= 0; col--)
  51. {
  52. matrix[row, col] = inputString[index % inputString.Length];
  53. index++;
  54. }
  55. }
  56. else
  57. {
  58. for (int col = 0; col < matrix.GetLength(1); col++)
  59. {
  60. matrix[row, col] = inputString[index % inputString.Length];
  61. index++;
  62. }
  63. }
  64. numberOfRows++;
  65. }
  66. }
  67.  
  68. private static void FireAShot(char[,] matrix, int impactRow, int impactCol, int radius)
  69. {
  70. for (int row = 0; row < matrix.GetLength(0); row++)
  71. {
  72. for (int col = 0; col < matrix.GetLength(1); col++)
  73. {
  74. if (((row - impactRow) * (row - impactRow)) + ((col - impactCol) * (col - impactCol)) <= radius * radius)
  75. {
  76. matrix[row, col] = ' ';
  77. }
  78. }
  79. }
  80. }
  81.  
  82. private static void RunGravity(char[,] matrix)
  83. {
  84. while (true)
  85. {
  86. var isFallen = false;
  87.  
  88. for (int row = 1; row < matrix.GetLength(0); row++)
  89. {
  90. for (int col = 0; col < matrix.GetLength(1); col++)
  91. {
  92. if (matrix[row, col] == ' ' && matrix[row - 1, col] != ' ')
  93. {
  94. matrix[row, col] = matrix[row - 1, col];
  95. matrix[row - 1, col] = ' ';
  96. isFallen = true;
  97. }
  98. }
  99. }
  100.  
  101. if (!isFallen)
  102. {
  103. break;
  104. }
  105. }
  106. }
  107.  
  108. private static void PrintMatrix(char[,] matrix)
  109. {
  110. var sb = new StringBuilder();
  111.  
  112. for (int row = 0; row < matrix.GetLength(0); row++)
  113. {
  114. for (int col = 0; col < matrix.GetLength(1); col++)
  115. {
  116. sb.Append(matrix[row, col]);
  117. }
  118.  
  119. sb.AppendLine();
  120. }
  121.  
  122. Console.WriteLine(sb.ToString().TrimEnd());
  123. }
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement