Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _6._Target_Practice
- {
- public class Program
- {
- public static void Main()
- {
- var sizes = Console.ReadLine()
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- var rows = sizes[0];
- var cols = sizes[1];
- var snakeString = Console.ReadLine();
- var matrix = new char[rows,cols];
- FillingStairsWithSnakes(matrix, snakeString);
- var bombPositionAndRadius = Console.ReadLine()
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- KillingTheSnakes(matrix, bombPositionAndRadius);
- RearangeMatrix(matrix);
- PrintTheMatrix(matrix);
- }
- public static void FillingStairsWithSnakes(char[,]matrix, string snakeString)
- {
- var snakeIndex = 0;
- var rowIndex = 0;
- for (int row = matrix.GetLength(0) - 1; row >= 0; row--)
- {
- if (rowIndex % 2 == 0)
- {
- for (int col = matrix.GetLength(1) - 1; col >= 0; col--)
- {
- matrix[row, col] = snakeString[snakeIndex++ % snakeString.Length];
- }
- rowIndex++;
- }
- else
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- matrix[row, col] = snakeString[snakeIndex++ % snakeString.Length];
- }
- rowIndex++;
- }
- }
- }
- public static void KillingTheSnakes(char[,] matrix, int[] bombPositionAndRadius)
- {
- var bombRadius = bombPositionAndRadius[2];
- var bombRow = bombPositionAndRadius[0];
- var bombCol = bombPositionAndRadius[1];
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- var a = bombRow - row;
- var b = bombCol - col;
- double distance = Math.Sqrt(a * a + b * b);
- if (distance <= bombRadius)
- {
- matrix[row, col] = ' ';
- }
- }
- }
- }
- public static void RearangeMatrix(char[,] matrix)
- {
- for (int row = matrix.GetLength(0) - 1; row >= 0; row--)
- {
- for (int col = matrix.GetLength(1) - 1; col >= 0; col--)
- {
- if (matrix[row, col] == ' ')
- {
- var currentRow = row;
- while (matrix[currentRow, col] == ' ' && currentRow > 0)
- {
- matrix[row, col] = matrix[--currentRow, col];
- }
- matrix[currentRow, col] = ' ';
- }
- }
- }
- }
- public static void PrintTheMatrix(char[,] matrix)
- {
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- Console.Write(matrix[row,col]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement