Advertisement
butoff

Target Practice

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