daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jan 29th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Target_Practice
  5. {
  6.     class Program
  7.     {
  8.         private static bool IsInsideRadius(int checkRow, int checkCol, int impactRow, int impactCol, int shotRadius)
  9.         {
  10.             int deltaRow = checkRow - impactRow;
  11.             int deltaCol = checkCol - impactCol;
  12.  
  13.             bool isInRadius = deltaRow * deltaRow + deltaCol * deltaCol <= shotRadius * shotRadius;
  14.  
  15.             return isInRadius;
  16.         }
  17.         static void Main(string[] args)
  18.         {
  19.             var size = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  20.  
  21.             var snake = Console.ReadLine().ToCharArray();
  22.            
  23.             var shotParameters = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  24.  
  25.             var matrix = new string[size[0], size[1]];
  26.  
  27.             var impactRow = shotParameters[0];
  28.             var impactCol = shotParameters[1];
  29.             var radius = shotParameters[2];
  30.  
  31.             var currentRow = 0;
  32.             var snakeIndex = 0;
  33.  
  34.             for (int row = matrix.GetLength(0) - 1; row >= 0; row--, currentRow++)
  35.             {
  36.                 if (currentRow % 2 == 0)
  37.                 {
  38.                     for (int col = matrix.GetLength(1) - 1; col >= 0; col--)
  39.                     {
  40.                         if (snakeIndex == snake.Length)
  41.                         {
  42.                             snakeIndex = 0;
  43.                         }
  44.                         matrix[row, col] = snake[snakeIndex].ToString();
  45.                         snakeIndex++;
  46.  
  47.                     }
  48.                 }
  49.                 else
  50.                 {
  51.                     for (int col = 0; col < matrix.GetLength(1); col++)
  52.                     {
  53.                         if (snakeIndex == snake.Length)
  54.                         {
  55.                             snakeIndex = 0;
  56.                         }
  57.                         matrix[row, col] = snake[snakeIndex].ToString();
  58.                         snakeIndex++;
  59.  
  60.                     }
  61.                 }
  62.             }
  63.             for (int row = 0; row < matrix.GetLength(0); row++)
  64.             {
  65.                 for (int col = 0; col < matrix.GetLength(1); col++)
  66.                 {
  67.                     if (IsInsideRadius(row,col,impactRow,impactCol,radius))
  68.                     {
  69.                         matrix[row, col] = " ";
  70.                     }
  71.                 }
  72.             }
  73.  
  74.             for (int row = matrix.GetLength(0) - 1; row >= 0; row--)
  75.             {
  76.                 for (int col = 0; col < matrix.GetLength(1); col++)
  77.                 {
  78.                     if (matrix[row,col] != " ")
  79.                     {
  80.                         continue;
  81.                     }
  82.  
  83.                     var curRow = row-1;
  84.                     while (curRow>=0)
  85.                     {
  86.                         if (matrix[curRow,col] != " ")
  87.                         {
  88.                             matrix[row, col] = matrix[curRow, col];
  89.                             matrix[curRow, col] = " ";
  90.                             break;
  91.                         }
  92.                         curRow--;
  93.                     }
  94.                 }
  95.             }
  96.             for (int i = 0; i < matrix.GetLength(0); i++)
  97.             {
  98.                 for (int j = 0; j < matrix.GetLength(1); j++)
  99.                 {
  100.                     Console.Write(matrix[i, j]);
  101.                 }
  102.                 Console.WriteLine();
  103.             }
  104.         }
  105.     }
  106. }
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top