Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- public class Program
- {
- public static void Main()
- {
- int[] matrixArgs = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse).ToArray();
- int rows = matrixArgs[0];
- int cols = matrixArgs[1];
- string snakeString = Console.ReadLine().Trim();
- int[] shotParameters = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse).ToArray();
- int impactRow = shotParameters[0];
- int impactCol = shotParameters[1];
- int radius = shotParameters[2];
- char[,] matrix = new char[rows, cols];
- int snakeIndexCounter = 0;
- //Filling in the matrix based on the required pattern
- for (int rowIndex = rows - 1; rowIndex >= 0; rowIndex--)
- {
- if (rowIndex % 2 == 0)
- {
- for (int colIndex = cols - 1; colIndex >= 0; colIndex--)
- {
- matrix[rowIndex, colIndex] = snakeString[snakeIndexCounter];
- snakeIndexCounter++;
- if (snakeIndexCounter == snakeString.Length)
- {
- snakeIndexCounter = 0;
- }
- }
- }
- else
- {
- for (int colIndex = 0; colIndex < cols; colIndex++)
- {
- matrix[rowIndex, colIndex] = snakeString[snakeIndexCounter];
- snakeIndexCounter++;
- if (snakeIndexCounter == snakeString.Length)
- {
- snakeIndexCounter = 0;
- }
- }
- }
- }
- //Replace all characters in the blast area with a space
- for (int rowIndex = 0; rowIndex < rows; rowIndex++)
- {
- for (int colIndex = 0; colIndex < cols; colIndex++)
- {
- if ((rowIndex - impactRow)*(rowIndex - impactRow) + (colIndex - impactCol)*(colIndex - impactCol) <= radius*radius)
- {
- matrix[rowIndex, colIndex] = ' ';
- }
- }
- }
- //All characters start falling down until they land on other characters
- for (int coIndex = 0; coIndex < cols; coIndex++)
- {
- char[] temp = new char[rows];
- for (int rowsIndex = 0; rowsIndex < rows; rowsIndex++)
- {
- temp[rowsIndex] = matrix[rowsIndex, coIndex];
- }
- temp = temp.OrderByDescending(x => x == ' ').ToArray();
- for (int rowsIndex = 0; rowsIndex < rows; rowsIndex++)
- {
- matrix[rowsIndex, coIndex] = temp[rowsIndex];
- }
- }
- //Print out the final matrix
- for (int rowIndex = 0; rowIndex < rows; rowIndex++)
- {
- for (int colIndex = 0; colIndex < cols; colIndex++)
- {
- Console.Write(matrix[rowIndex, colIndex]);
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement