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;
- using System.Text.RegularExpressions;
- //using System.Collections.Generic;
- namespace Problem2
- {
- class Problem2
- {
- private static int _rows;
- private static int _cols;
- private static char[,] _matrix;
- static void Main(string[] args)
- {
- String[] p = Console.ReadLine().Trim().Split(' ');
- _rows = int.Parse(p[0]);
- _cols = int.Parse(p[1]);
- String snake = Console.ReadLine();
- _matrix = new char[_rows, _cols];
- PopulateMatrix(snake);
- String[] shot = Console.ReadLine().Split(' ');
- int shotRow = int.Parse(shot[0]);
- int shotCol = int.Parse(shot[1]);
- int shotRadius = int.Parse(shot[2]);
- MakeShot(shotRow, shotCol, shotRadius);
- ObjectsFall();
- PrintResults();
- }
- private static void PrintResults()
- {
- for (int row = 0; row < _rows; row++)
- {
- for (int col = 0; col < _cols; col++)
- {
- Console.Write(_matrix[row, col].ToString());
- }
- Console.WriteLine();
- }
- }
- private static void ObjectsFall()
- {
- for (int row = _rows - 2; row >= 0; row--)
- {
- for (int col = 0; col < _cols; col++)
- {
- int nextRow = row + 1;
- char current = _matrix[row, col];
- while (true)
- {
- char nextChar;
- try
- {
- nextChar = _matrix[nextRow, col];
- //if (nextChar == ' ' || nextChar == '\0')
- if (nextChar == ' ')
- {
- _matrix[nextRow, col] = current;
- _matrix[nextRow - 1, col] = ' ';
- current = _matrix[nextRow, col];
- nextRow++;
- continue;
- }
- break;
- }
- catch (Exception)
- {
- break;
- }
- }
- }
- }
- }
- private static void MakeShot(int shotRow, int shotCol, int shotRadius)
- {
- //(pointX - 1) * (pointX - 1) + (pointY - 1) * (pointY - 1) <= radius * radius;
- // (x - h)*(x - h) + (y - k)*(y - k) = r * r
- for (int row = 0; row < _rows; row++)
- {
- for (int col = 0; col < _cols; col++)
- {
- if (IsInCircle(shotRow, shotCol, row, col, shotRadius))
- {
- _matrix[row, col] = ' ';
- }
- }
- }
- //_matrix[shotRow, shotCol] = ' ';
- ////ShotLeft(shotRow, shotCol, shotRadius);
- ////ShotRight(shotRow, shotCol, shotRadius);
- ////ShotUp(shotRow, shotCol, shotRadius);
- ////ShotDown(shotRow, shotCol, shotRadius);
- ////ShotLeftUp(shotRow, shotCol, shotRadius);
- ////ShotRightUp(shotRow, shotCol, shotRadius);
- ////ShotLeftDown(shotRow, shotCol, shotRadius);
- ////ShotRightDown(shotRow, shotCol, shotRadius);
- }
- private static bool IsInCircle(int startX, int startY, int x, int y, int r)
- {
- return ((x - startX) * (x - startX) + (y - startY) * (y - startY)) <= r * r;
- }
- private static void ShotRightDown(int shotRow, int shotCol, int shotRadius)
- {
- int startRow = shotRow;
- int startCol = shotCol;
- if (shotRadius == 1)
- {
- try
- {
- _matrix[startRow + 1, startCol + 1] = ' ';
- return;
- }
- catch (Exception)
- {
- return;
- }
- }
- for (int i = 1; i < shotRadius; i++)
- {
- try
- {
- _matrix[startRow + i, startCol + i] = ' ';
- }
- catch (Exception)
- {
- break;
- }
- }
- }
- private static void ShotLeftDown(int shotRow, int shotCol, int shotRadius)
- {
- int startRow = shotRow;
- int startCol = shotCol;
- if (shotRadius == 1)
- {
- try
- {
- _matrix[startRow + 1, startCol - 1] = ' ';
- return;
- }
- catch (Exception)
- {
- return;
- }
- }
- for (int i = 1; i < shotRadius; i++)
- {
- try
- {
- _matrix[startRow + i, startCol - i] = ' ';
- }
- catch (Exception)
- {
- break;
- }
- }
- }
- private static void ShotRightUp(int shotRow, int shotCol, int shotRadius)
- {
- int startRow = shotRow;
- int startCol = shotCol;
- if (shotRadius == 1)
- {
- try
- {
- _matrix[startRow - 1, startCol + 1] = ' ';
- return;
- }
- catch (Exception)
- {
- return;
- }
- }
- for (int i = 1; i < shotRadius; i++)
- {
- try
- {
- _matrix[startRow - i, startCol + i] = ' ';
- }
- catch (Exception)
- {
- break;
- }
- }
- }
- private static void ShotLeftUp(int shotRow, int shotCol, int shotRadius)
- {
- int startRow = shotRow;
- int startCol = shotCol;
- if (shotRadius == 1)
- {
- try
- {
- _matrix[startRow - 1, startCol - 1] = ' ';
- return;
- }
- catch (Exception)
- {
- return;
- }
- }
- for (int i = 1; i < shotRadius; i++)
- {
- try
- {
- _matrix[startRow - i, startCol - i] = ' ';
- }
- catch (Exception)
- {
- break;
- }
- }
- }
- private static void ShotDown(int shotRow, int shotCol, int shotRadius)
- {
- int startIndex = shotRow;
- for (int i = 1; i <= shotRadius; i++)
- {
- try
- {
- _matrix[startIndex + i, shotCol] = ' ';
- }
- catch (Exception)
- {
- break;
- }
- }
- }
- private static void ShotUp(int shotRow, int shotCol, int shotRadius)
- {
- int startIndex = shotRow;
- for (int i = 1; i <= shotRadius; i++)
- {
- try
- {
- _matrix[startIndex - i, shotCol] = ' ';
- }
- catch (Exception)
- {
- break;
- }
- }
- }
- private static void ShotRight(int shotRow, int shotCol, int shotRadius)
- {
- int startIndex = shotCol;
- for (int i = 1; i <= shotRadius; i++)
- {
- try
- {
- _matrix[shotRow, startIndex + i] = ' ';
- }
- catch (Exception)
- {
- break;
- }
- }
- }
- private static void ShotLeft(int shotRow, int shotCol, int shotRadius)
- {
- int startIndex = shotCol;
- for (int i = 1; i <= shotRadius; i++)
- {
- try
- {
- _matrix[shotRow, startIndex - i] = ' ';
- }
- catch (Exception)
- {
- break;
- }
- }
- }
- private static void PopulateMatrix(String snake)
- {
- int snakeIndex = 0;
- int startRow = _rows - 1;
- int startCol = _cols - 1;
- int flag = 0;
- for (int row = _rows - 1; row >= 0; row--)
- {
- if (flag == 0)
- {
- for (int col = _cols - 1; col >= 0; col--)
- {
- if (snakeIndex >= snake.Length)
- {
- snakeIndex = 0;
- }
- _matrix[row, col] = snake[snakeIndex];
- snakeIndex++;
- }
- flag = 1;
- }
- else
- {
- for (int col = 0; col < _cols; col++)
- {
- if (snakeIndex >= snake.Length)
- {
- snakeIndex = 0;
- }
- _matrix[row, col] = snake[snakeIndex];
- snakeIndex++;
- }
- flag = 0;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement