Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace TargetPractice
- {
- using System;
- using System.Linq;
- using System.Text;
- public class Startup
- {
- private static char[,] matrix;
- private static int rowsOfMatrix;
- private static int colsOfMatrix;
- public static void Main()
- {
- int[] dimensionsOfMatrix = SplitStringToIntegerArray();
- rowsOfMatrix = dimensionsOfMatrix[0];
- colsOfMatrix = dimensionsOfMatrix[1];
- matrix = new char[rowsOfMatrix, colsOfMatrix];
- string snakeWord = Console.ReadLine();
- int indexOfSnakeWord = 0;
- for (int currentRow = 0; currentRow < rowsOfMatrix; currentRow++)
- {
- if (currentRow % 2 == 0)
- {
- for (int currentCol = colsOfMatrix - 1; currentCol >= 0; currentCol--)
- {
- matrix[rowsOfMatrix - 1 - currentRow, currentCol] = snakeWord[indexOfSnakeWord++ % snakeWord.Length];
- }
- }
- else
- {
- for (int currentCol = 0; currentCol < colsOfMatrix; currentCol++)
- {
- matrix[rowsOfMatrix - 1 - currentRow, currentCol] = snakeWord[indexOfSnakeWord++ % snakeWord.Length];
- }
- }
- }
- int[] shotRadius = SplitStringToIntegerArray();
- int targetRow = shotRadius[0];
- int targetCol = shotRadius[1];
- int radius = shotRadius[2];
- for (int currentRow = 0; currentRow < rowsOfMatrix; currentRow++)
- {
- for (int currentCol = 0; currentCol < colsOfMatrix; currentCol++)
- {
- if (CellIsInRangeOfTheShot(currentRow, currentCol, targetRow, targetCol, radius))
- {
- matrix[currentRow, currentCol] = ' ';
- }
- }
- }
- for (int currentRow = 0; currentRow < rowsOfMatrix; currentRow++)
- {
- for (int currentCol = 0; currentCol < colsOfMatrix; currentCol++)
- {
- ActivateGravityOnCell(currentRow, currentCol);
- }
- }
- PrintMatrix();
- }
- private static void ActivateGravityOnCell(int row, int col)
- {
- while (LowerCellIsEmptyOrValid(row + 1, col))
- {
- for (int currentRow = row + 1; currentRow >= 1; currentRow--)
- {
- matrix[currentRow, col] = matrix[currentRow - 1, col];
- }
- matrix[0, col] = ' ';
- row++;
- }
- }
- private static bool LowerCellIsEmptyOrValid(int row, int col)
- {
- return row >= 0 && row < rowsOfMatrix &&
- col >= 0 && col < colsOfMatrix &&
- matrix[row, col] == ' ';
- }
- private static bool CellIsInRangeOfTheShot(int currentRow, int currentCol, int targetRow, int targetCol, int radius)
- {
- bool cellIsInsideRangeOfTheShot = Math.Pow(currentRow - targetRow, 2) +
- Math.Pow(currentCol - targetCol, 2) <= Math.Pow(radius, 2);
- return cellIsInsideRangeOfTheShot;
- }
- private static int[] SplitStringToIntegerArray()
- {
- return Console.ReadLine()
- .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- }
- private static void PrintMatrix()
- {
- StringBuilder result = new StringBuilder();
- for (int currentRow = 0; currentRow < matrix.GetLength(0); currentRow++)
- {
- for (int currentCol = 0; currentCol < matrix.GetLength(1); currentCol++)
- {
- result.Append(matrix[currentRow, currentCol]);
- }
- result.AppendLine();
- }
- Console.Write(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement