Advertisement
elena1234

Jedi Galaxy

Mar 13th, 2021 (edited)
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.73 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace JediGalaxy
  5. {
  6.    public class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] arrayInfo = Console.ReadLine().Split().Select(int.Parse).ToArray();
  11.             int matrixRows = arrayInfo[0];
  12.             int matrixCols = arrayInfo[1];
  13.             int[,] matrix = CreateMatrix(matrixRows, matrixCols);
  14.             long sumOfStars = 0;
  15.             string line = Console.ReadLine();
  16.             while (line != "Let the Force be with you")
  17.             {
  18.                 int[] ivoCoordinates = line.Split().Select(int.Parse).ToArray();
  19.                 int ivoRow = ivoCoordinates[0];
  20.                 int ivoCol = ivoCoordinates[1];
  21.            
  22.                 int[] evilCoordinates = Console.ReadLine().Split().Select(int.Parse).ToArray();
  23.                 int evilRow = evilCoordinates[0];
  24.                 int evilCol = evilCoordinates[1];
  25.  
  26.                 while(evilRow >= 0 && evilCol >= 0)
  27.                 {                    
  28.                     EvilDestroysStars(matrixRows, matrixCols, matrix, evilRow, evilCol);
  29.                     evilRow--;
  30.                     evilCol--;
  31.                 }
  32.  
  33.                 while (ivoRow >= 0 && ivoCol <= matrixCols - 1)
  34.                 {                  
  35.                     sumOfStars = IvoCollectsStars(matrixRows, matrixCols, matrix, sumOfStars, ivoRow, ivoCol);
  36.                     ivoRow--;
  37.                     ivoCol++;
  38.                 }
  39.  
  40.                 line = Console.ReadLine();
  41.             }
  42.  
  43.             Console.WriteLine(sumOfStars);
  44.         }
  45.  
  46.         private static long IvoCollectsStars(int matrixRows, int matrixCols, int[,] matrix, long sumOfStars, int ivoRow, int ivoCol)
  47.         {
  48.             if (ivoRow >= 0 && ivoRow < matrixRows && ivoCol >= 0 && ivoCol < matrixCols)
  49.             {
  50.                 sumOfStars += matrix[ivoRow, ivoCol];
  51.             }
  52.  
  53.             return sumOfStars;
  54.         }
  55.  
  56.         private static void EvilDestroysStars(int matrixRows, int matrixCols, int[,] matrix, int evilRow, int evilCol)
  57.         {
  58.             if (evilRow >= 0 && evilRow < matrixRows && evilCol >= 0 && evilCol < matrixCols)
  59.             {
  60.                 matrix[evilRow, evilCol] = 0;
  61.             }
  62.         }
  63.  
  64.         private static int[,] CreateMatrix(int matrixRows, int matrixCols)
  65.         {
  66.             int[,] matrix = new int[matrixRows, matrixCols];
  67.             int value = 0;
  68.             for (int row = 0; row < matrixRows; row++)
  69.             {
  70.                 for (int col = 0; col < matrixCols; col++)
  71.                 {
  72.                     matrix[row, col] = value;
  73.                     value++;
  74.                 }
  75.             }
  76.  
  77.             return matrix;
  78.         }
  79.     }
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement