Advertisement
gabi11

Multidimensional Arrays - 06. Bomb the Basement

May 12th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.14 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace Advanced
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var dimentions = Console.ReadLine()
  14.                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  15.                 .Select(int.Parse)
  16.                 .ToArray();
  17.  
  18.             int rows = dimentions[0];
  19.             int cols = dimentions[1];
  20.  
  21.             var matrix = new int[rows][];
  22.  
  23.             for (int row = 0; row < rows; row++)
  24.             {
  25.                 matrix[row] = new int[cols];
  26.             }
  27.  
  28.             var bomb = Console.ReadLine()
  29.                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  30.                 .Select(int.Parse)
  31.                 .ToArray();
  32.  
  33.             int bombRow = bomb[0];
  34.             int bombCol = bomb[1];
  35.             int radius = bomb[2];
  36.  
  37.             for (int row = 0; row < rows; row++)
  38.             {
  39.                 for (int col = 0; col < cols; col++)
  40.                 {
  41.                     double distance = Math.Sqrt(Math.Pow(row - bombRow, 2) + Math.Pow(col - bombCol, 2));
  42.  
  43.                     if (distance <= radius)
  44.                     {
  45.                         matrix[row][col] = 1;
  46.                     }
  47.                 }
  48.             }
  49.  
  50.             var secondMatrix = new int[cols][];
  51.  
  52.             for (int row = 0; row < cols; row++)
  53.             {
  54.                 secondMatrix[row] = new int[rows];
  55.  
  56.                 for (int col = 0; col < rows; col++)
  57.                 {
  58.                     secondMatrix[row][col] = matrix[col][row];
  59.                 }
  60.  
  61.                 secondMatrix[row] = secondMatrix[row].OrderByDescending(x => x).ToArray();
  62.             }
  63.  
  64.             for (int row = 0; row < rows; row++)
  65.             {
  66.                 for (int col = 0; col < cols; col++)
  67.                 {
  68.                     matrix[row][col] = secondMatrix[col][row];
  69.                 }
  70.  
  71.             }
  72.  
  73.  
  74.             Console.WriteLine(string.Join(Environment.NewLine, matrix.Select(r => string.Join("", r))));
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement