Advertisement
dobroslav-atanasov

Untitled

Feb 2nd, 2018
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. namespace _06._TargetPractice
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. public class Startup
  8. {
  9. private static int rows;
  10. private static int columns;
  11. public static void Main()
  12. {
  13. var rowsCols = Console.ReadLine()
  14. .Split(new[] { ' ' },
  15. StringSplitOptions.RemoveEmptyEntries)
  16. .Select(int.Parse)
  17. .ToArray();
  18. rows = rowsCols[0];
  19. columns = rowsCols[1];
  20.  
  21. var matrix = new char[rows, columns];
  22.  
  23. var snake = Console.ReadLine().ToCharArray();
  24. var shotParams = Console.ReadLine()
  25. .Split(new[] { ' ' },
  26. StringSplitOptions.RemoveEmptyEntries)
  27. .Select(int.Parse)
  28. .ToArray();
  29.  
  30. var impactRow = shotParams[0];
  31. var impactColumn = shotParams[1];
  32. var radius = shotParams[2];
  33.  
  34. var snakeIndex = 0;
  35.  
  36. FillInMatrix(snakeIndex, snake, matrix);
  37. Shoot(impactRow, impactColumn, radius, matrix);
  38. StartFallin(matrix);
  39. Print(matrix);
  40. }
  41.  
  42. private static void Print(char[,] matrix)
  43. {
  44. for (int i = 0; i < rows; i++)
  45. {
  46. for (int j = 0; j < columns; j++)
  47. {
  48. Console.Write(matrix[i, j]);
  49. }
  50. Console.WriteLine();
  51. }
  52. }
  53.  
  54. private static void StartFallin(char[,] matrix)
  55. {
  56. for (int col = 0; col < matrix.GetLength(1); col++)
  57. {
  58. List<char> list = new List<char>();
  59. for (int row = matrix.GetLength(0) - 1; row >= 0; row--)
  60. {
  61. if (matrix[row, col] != ' ')
  62. {
  63. list.Add(matrix[row, col]);
  64. }
  65. }
  66.  
  67. for (int i = list.Count; i < matrix.GetLength(0); i++)
  68. {
  69. list.Add(' ');
  70. }
  71. for (int row = 0; row < matrix.GetLength(0); row++)
  72. {
  73. matrix[row, col] = list[list.Count - 1 - row];
  74. }
  75. }
  76. }
  77.  
  78. private static void Shoot(int impactRow, int impactColumn, int radius, char[,] matrix)
  79. {
  80. matrix[impactRow, impactColumn] = ' ';
  81. //Calculate radius
  82. for (int row = 0; row < rows; row++)
  83. {
  84. for (int col = 0; col < columns; col++)
  85. {
  86. if ((row - impactRow) *
  87. (row - impactRow) +
  88. (col - impactColumn) *
  89. (col - impactColumn)
  90. <= radius * radius)
  91. {
  92. matrix[row, col] = ' ';
  93. }
  94. }
  95. }
  96.  
  97. }
  98.  
  99. private static void FillInMatrix(int snakeIndex, char[] snake, char[,] matrix)
  100. {
  101. var counter = 0;
  102. for (int rowIndex = rows; rowIndex > 0; rowIndex--)
  103. {
  104. if (counter % 2 == 0)
  105. {
  106. for (int colIndex = columns; colIndex > 0; colIndex--) //right to left
  107. {
  108. if (snakeIndex <= snake.Length - 1)
  109. {
  110. matrix[rowIndex - 1, colIndex - 1] = snake[snakeIndex];
  111. snakeIndex++;
  112. }
  113. else
  114. {
  115. colIndex++;
  116. snakeIndex = 0;
  117. }
  118. }
  119. }
  120. //left to right
  121. rowIndex--;
  122. if (rowIndex == 0)
  123. {
  124. break;
  125. }
  126. for (int colIndex = 0; colIndex < columns; colIndex++)
  127. {
  128. if (snakeIndex <= snake.Length - 1)
  129. {
  130. matrix[rowIndex - 1, colIndex] = snake[snakeIndex];
  131. snakeIndex++;
  132. }
  133. else
  134. {
  135. colIndex--;
  136. snakeIndex = 0;
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement