Advertisement
Guest User

Untitled

a guest
Jun 1st, 2015
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5.  
  6. class Problem2
  7. {
  8.     static void Main()
  9.     {
  10.         int[] dimensions = Console.ReadLine().Split().Select(int.Parse).ToArray();
  11.         int n = dimensions[0];
  12.         int m = dimensions[1];
  13.         string snake = Console.ReadLine();
  14.  
  15.         char[,] stairs = new char[n, m];
  16.         FillMatrix(stairs, snake, n, m);
  17.         TakeAShot(stairs);
  18.         FallingDown(stairs, n, m);
  19.         for (int i = 0; i < n; i++)
  20.         {
  21.             for (int j = 0; j < m; j++)
  22.             {
  23.                 Console.Write(stairs[i, j]);
  24.             }
  25.             Console.WriteLine();
  26.         }
  27.  
  28.     }
  29.  
  30.     private static void FallingDown(char[,] stairs, int n, int m)
  31.     {
  32.         bool fallen = false;
  33.         do
  34.         {
  35.             fallen = false;
  36.             for (int row = 0; row < n - 1; row++)
  37.             {
  38.                 for (int col = 0; col < m; col++)
  39.                 {
  40.                     if (stairs[row, col] != ' ' && stairs[row + 1, col] == ' ')
  41.                     {
  42.                         stairs[row + 1, col] = stairs[row, col];
  43.                         stairs[row, col] = ' ';
  44.                         fallen = true;
  45.                     }
  46.                 }
  47.             }
  48.         } while (fallen);
  49.     }
  50.  
  51.     private static void TakeAShot(char[,] stairs)
  52.     {
  53.         int[] shotParams = Console.ReadLine().Split().Select(int.Parse).ToArray();
  54.         int x = shotParams[0];
  55.         int y = shotParams[1];
  56.         int r = shotParams[2];
  57.         for (int i = x - r; i <= x + r; i++)
  58.         {
  59.             for (int j = y - r; j <= y + r; j++)
  60.             {
  61.                 try
  62.                 {
  63.                     if (Math.Pow(x-i, 2) + Math.Pow(y - j, 2) <= r*r)
  64.                     {
  65.                         stairs[i, j] = ' ';
  66.                     }
  67.                 }
  68.                 catch (Exception)
  69.                 {
  70.  
  71.                     continue;
  72.                 }
  73.             }
  74.         }
  75.     }
  76.  
  77.     private static void FillMatrix(char[,] stairs, string snake, int n, int m)
  78.     {
  79.         int letter = 0;
  80.         for (int i = n - 1; i >= 0; i--)
  81.         {
  82.             if ((n - 1 - i) % 2 == 0)
  83.             {
  84.                 for (int j = m - 1; j >= 0; j--)
  85.                 {
  86.                     stairs[i, j] = snake[letter % snake.Length];
  87.                     letter++;
  88.                 }
  89.             }
  90.             else
  91.             {
  92.                 for (int j = 0; j < m; j++)
  93.                 {
  94.                     stairs[i, j] = snake[letter % snake.Length];
  95.                     letter++;
  96.                 }
  97.             }
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement