-Annie-

JediGalaxy

Jun 16th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.66 KB | None | 0 0
  1. namespace JediGalaxy
  2. {
  3.     using System;
  4.     using System.Linq;
  5.  
  6.     public class JediGalaxy
  7.     {
  8.         public static void Main()
  9.         {
  10.             long ivoStarValue = 0;
  11.             int[] matrixDimentions = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.             int[,] galaxy = new int[matrixDimentions[0], matrixDimentions[1]];
  13.  
  14.             FillMatrix(galaxy);
  15.  
  16.             string ivoCoordinates = Console.ReadLine();
  17.  
  18.             while (ivoCoordinates != "Let the Force be with you")
  19.             {
  20.                 string evilCoordinates = Console.ReadLine();
  21.                 int[] ivoParsedCoordinates = ivoCoordinates.Split().Select(int.Parse).ToArray();
  22.                 int[] evilParsedCoordinates = evilCoordinates.Split().Select(int.Parse).ToArray();
  23.  
  24.                 int currentIvoRow = ivoParsedCoordinates[0];
  25.                 int currentIvoColumn = ivoParsedCoordinates[1];
  26.  
  27.                 int currentEvilRow = evilParsedCoordinates[0];
  28.                 int currentEvilColumn = evilParsedCoordinates[1];
  29.  
  30.                 while (currentEvilRow >= 0 && currentEvilColumn >= 0)
  31.                 {
  32.                     if (isInMatrix(galaxy, currentEvilRow, currentEvilColumn))
  33.                     {
  34.                         galaxy[currentEvilRow, currentEvilColumn] = 0;
  35.                     }
  36.  
  37.                     currentEvilRow--;
  38.                     currentEvilColumn--;
  39.                 }
  40.  
  41.                 while (currentIvoRow >= 0 && currentIvoColumn<galaxy.GetLength(1))
  42.                 {
  43.                     if (isInMatrix(galaxy, currentIvoRow, currentIvoColumn))
  44.                     {
  45.                         ivoStarValue += galaxy[currentIvoRow, currentIvoColumn];
  46.                     }
  47.  
  48.                     currentIvoRow--;
  49.                     currentIvoColumn++;
  50.                 }
  51.  
  52.                 ivoCoordinates = Console.ReadLine();
  53.             }
  54.  
  55.             Console.WriteLine(ivoStarValue);
  56.         }
  57.  
  58.         private static bool isInMatrix(int[,] galaxy, int givenRow, int givenColumn)
  59.         {
  60.             bool result = givenRow >= 0
  61.                 && givenRow < galaxy.GetLength(0)
  62.                 && givenColumn >= 0
  63.                 && givenColumn < galaxy.GetLength(1);
  64.  
  65.             return result;
  66.         }
  67.  
  68.         private static void FillMatrix(int[,] galaxy)
  69.         {
  70.             int currentCount = 0;
  71.  
  72.             for (int i = 0; i < galaxy.GetLength(0); i++)
  73.             {
  74.                 for (int j = 0; j < galaxy.GetLength(1); j++)
  75.                 {
  76.                     galaxy[i, j] = currentCount;
  77.                     currentCount++;
  78.                 }
  79.             }
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment