Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.27 KB | None | 0 0
  1. namespace BasicsExamDec
  2. {
  3.     using System;
  4.     using System.Linq;
  5.  
  6.     public sealed class Exam
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] dimensions = Console.ReadLine()
  11.                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  12.                 .Select(int.Parse)
  13.                 .ToArray();
  14.             string word = Console.ReadLine();
  15.             int[] shotPareameters = Console.ReadLine()
  16.                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  17.                .Select(int.Parse)
  18.                .ToArray();
  19.  
  20.             char[,] matrix = new char[dimensions[0], dimensions[1]];
  21.             int impactRow = shotPareameters[0];
  22.             int impactCol = shotPareameters[1];
  23.             int radius = shotPareameters[2];
  24.  
  25.             int index = 0;
  26.             int checker = 0;
  27.  
  28.             for (int row = matrix.GetLength(0) - 1; row >= 0; row--)
  29.             {
  30.                 checker++;
  31.  
  32.                 if (checker % 2 == 0)
  33.                 {
  34.                     for (int col = 0; col < matrix.GetLength(1); col++)
  35.                     {
  36.                         matrix[row, col] = word[index];
  37.                         index++;
  38.  
  39.                         if (index == word.Length)
  40.                         {
  41.                             index = 0;
  42.                         }
  43.                     }
  44.                 }
  45.                 else
  46.                 {
  47.                     for (int col = matrix.GetLength(1) - 1; col >= 0; col--)
  48.                     {
  49.                         matrix[row, col] = word[index];
  50.                         index++;
  51.  
  52.                         if (index == word.Length)
  53.                         {
  54.                             index = 0;
  55.                         }
  56.                     }
  57.                 }
  58.             }
  59.  
  60.             for (int row = 0; row < matrix.GetLength(0); row++)
  61.             {
  62.                 for (int col = 0; col < matrix.GetLength(1); col++)
  63.                 {
  64.                     bool isInImpactZone =
  65.                         (row - impactRow) * (row - impactRow) + (col - impactCol) * (col - impactCol) <= radius * radius;
  66.  
  67.                     if (isInImpactZone)
  68.                     {
  69.                         matrix[row, col] = ' ';
  70.                     }
  71.                 }
  72.             }
  73.  
  74.             bool isFallen = false;
  75.             do
  76.             {
  77.                 isFallen = false;
  78.  
  79.                 for (int row = 0; row < matrix.GetLength(0) - 1; row++)
  80.                 {
  81.                     for (int col = 0; col < matrix.GetLength(1); col++)
  82.                     {
  83.                         if (matrix[row,col] != ' ' && matrix[row+1, col]==' ')
  84.                         {
  85.                             matrix[row + 1, col] = matrix[row, col];
  86.                             matrix[row, col] = ' ';
  87.                             isFallen = true;
  88.                         }
  89.                     }
  90.                 }
  91.  
  92.             } while (isFallen);
  93.  
  94.             for (int r = 0; r < matrix.GetLength(0); r++)
  95.             {
  96.                 for (int c = 0; c < matrix.GetLength(1); c++)
  97.                 {
  98.                     Console.Write(matrix[r, c]);
  99.                 }
  100.  
  101.                 Console.WriteLine();
  102.             }
  103.         }
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement