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;
- namespace TargetPractice
- {
- class Program
- {
- public static bool IsInRectangle(double centerX, double centerY, double radius,
- double x, double y)
- {
- return x >= centerX - radius && x <= centerX + radius &&
- y >= centerY - radius && y <= centerY + radius;
- }
- public static bool IsPointInCircle(double centerX, double centerY,
- double radius, double x, double y)
- {
- if (IsInRectangle(centerX, centerY, radius, x, y))
- {
- double dx = centerX - x;
- double dy = centerY - y;
- dx *= dx;
- dy *= dy;
- double distanceSquared = dx + dy;
- double radiusSquared = radius * radius;
- return distanceSquared <= radiusSquared;
- }
- return false;
- }
- static void Main(string[] args)
- {
- string firstLine = Console.ReadLine();
- string[] dimensionsArray = firstLine.Split(' ');
- int rows = int.Parse(dimensionsArray[0]);
- int cols = int.Parse(dimensionsArray[1]);
- string snake = Console.ReadLine();
- string[] shotParams = Console.ReadLine().Split(' ');
- int impactRow = int.Parse(shotParams[0]);
- int impactCol = int.Parse(shotParams[1]);
- int radius = int.Parse(shotParams[2]);
- char[,] matrix = new char[rows, cols];
- int countLine = -1;
- int countSnakeChar = -1;
- for (int i = rows - 1; i >= 0; i--)
- {
- countLine++;
- if (countLine%2 == 0)
- {
- for (int j = cols - 1; j >= 0; j--)
- {
- countSnakeChar++;
- if (countSnakeChar == snake.Length)
- {
- countSnakeChar = 0;
- }
- matrix[i, j] = snake[countSnakeChar];
- }
- }
- else
- {
- for (int j = 0; j < cols; j++)
- {
- countSnakeChar++;
- if (countSnakeChar == snake.Length)
- {
- countSnakeChar = 0;
- }
- matrix[i, j] = snake[countSnakeChar];
- }
- }
- }
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < cols; j++)
- {
- if (IsPointInCircle(impactRow, impactCol, radius, i, j))
- {
- matrix[i, j] = ' ';
- }
- }
- }
- for (int a = 0; a < rows; a++)
- {
- for (int i = rows - 2; i >= 0; i--)
- {
- for (int j = 0; j < cols; j++)
- {
- var ch = matrix[i, j];
- var under = matrix[i + 1, j];
- if (under == ' ')
- {
- matrix[i + 1, j] = ch;
- matrix[i, j] = ' ';
- }
- }
- }
- }
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < cols; j++)
- {
- Console.Write(matrix[i, j] + "");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement