Advertisement
dobroslav-atanasov

Untitled

Jan 31st, 2018
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.19 KB | None | 0 0
  1. namespace _06._TargetPractice
  2. {
  3.     using System;
  4.  
  5.     public class Startup
  6.     {
  7.         public static void Main()
  8.         {
  9.             string[] input = Console.ReadLine().Split();
  10.             int rows = int.Parse(input[0]);
  11.             int cols = int.Parse(input[1]);
  12.  
  13.             char[] snake = Console.ReadLine().ToCharArray();
  14.             string[] shot = Console.ReadLine().Split();
  15.             int shotRow = int.Parse(shot[0]);
  16.             int shotColumn = int.Parse(shot[1]);
  17.             int radius = int.Parse(shot[2]);
  18.  
  19.             char[,] matrix = new char[rows, cols];
  20.             //----------------------------------------------------------populate matrix
  21.             int index = 0;
  22.             bool rightToLeft = true;
  23.             for (int r = rows - 1; r >= 0; r--)
  24.             {
  25.                 if (rightToLeft)
  26.                 {
  27.                     for (int c = cols - 1; c >= 0; c--)
  28.                     {
  29.                         if (index == snake.Length)
  30.                         {
  31.                             index = 0;
  32.                         }
  33.                         matrix[r, c] = snake[index];
  34.                         index++;
  35.                     }
  36.                 }
  37.                 else
  38.                 {
  39.                     for (int c = 0; c < cols; c++)
  40.                     {
  41.                         if (index == snake.Length)
  42.                         {
  43.                             index = 0;
  44.                         }
  45.                         matrix[r, c] = snake[index];
  46.                         index++;
  47.                     }
  48.                 }
  49.                 rightToLeft = !rightToLeft;
  50.             }
  51.  
  52.             //-----------------------------------------------------Pythagorean Theorem
  53.             for (int row = 0; row < matrix.GetLength(0); row++)
  54.             {
  55.                 for (int col = 0; col < matrix.GetLength(1); col++)
  56.                 {
  57.                     double distance = Math.Sqrt(Math.Pow(row - shotRow, 2) + Math.Pow(col - shotColumn, 2));
  58.                     if (distance <= radius)
  59.                     {
  60.                         matrix[row, col] = ' ';
  61.                     }
  62.                 }
  63.             }
  64.  
  65.             //-----------------------------------------------------delete lower triangle
  66.             //int correction = 0;
  67.             //for (int r = shotRow; r <= shotRow + radius; r++)
  68.             //{
  69.             //    for (int c = shotColumn - radius + correction; c <= shotColumn + radius - correction; c++)
  70.             //    {
  71.             //        if (r < rows && c >= 0 && c < cols)
  72.             //        {
  73.             //            matrix[r, c] = ' ';
  74.             //        }
  75.             //    }
  76.             //    correction++;
  77.             //}
  78.             ////-----------------------------------------------------delete higher triangle
  79.             //correction = 0;
  80.             //for (int r = shotRow; r >= shotRow - radius; r--)
  81.             //{
  82.             //    for (int c = shotColumn - radius + correction; c <= shotColumn + radius - correction; c++)
  83.             //    {
  84.             //        if (r >= 0 && c >= 0 && c < cols && r < rows)
  85.             //        {
  86.             //            matrix[r, c] = ' ';
  87.             //        }
  88.             //    }
  89.             //    correction++;
  90.             //}
  91.             //-------------------------------------------------------check for whitespaces
  92.             for (int c = 0; c < cols; c++)
  93.             {
  94.                 for (int i = 0; i < rows; i++)
  95.                 {
  96.                     for (int r = rows - 1; r > 0; r--)
  97.                     {
  98.                         if (matrix[r, c] == ' ')
  99.                         {
  100.                             matrix[r, c] = matrix[r - 1, c];
  101.                             matrix[r - 1, c] = ' ';
  102.                         }
  103.                     }
  104.                 }
  105.             }
  106.             //-------------------------------------------------------print result
  107.             for (int i = 0; i < rows; i++)
  108.             {
  109.                 for (int j = 0; j < cols; j++)
  110.                 {
  111.                     Console.Write(matrix[i, j]);
  112.                 }
  113.                 Console.WriteLine();
  114.             }
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement