Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace JediGalaxy
- {
- using System;
- using System.Linq;
- public class JediGalaxy
- {
- public static void Main()
- {
- long ivoStarValue = 0;
- int[] matrixDimentions = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int[,] galaxy = new int[matrixDimentions[0], matrixDimentions[1]];
- FillMatrix(galaxy);
- string ivoCoordinates = Console.ReadLine();
- while (ivoCoordinates != "Let the Force be with you")
- {
- string evilCoordinates = Console.ReadLine();
- int[] ivoParsedCoordinates = ivoCoordinates.Split().Select(int.Parse).ToArray();
- int[] evilParsedCoordinates = evilCoordinates.Split().Select(int.Parse).ToArray();
- int currentIvoRow = ivoParsedCoordinates[0];
- int currentIvoColumn = ivoParsedCoordinates[1];
- int currentEvilRow = evilParsedCoordinates[0];
- int currentEvilColumn = evilParsedCoordinates[1];
- while (currentEvilRow >= 0 && currentEvilColumn >= 0)
- {
- if (isInMatrix(galaxy, currentEvilRow, currentEvilColumn))
- {
- galaxy[currentEvilRow, currentEvilColumn] = 0;
- }
- currentEvilRow--;
- currentEvilColumn--;
- }
- while (currentIvoRow >= 0 && currentIvoColumn<galaxy.GetLength(1))
- {
- if (isInMatrix(galaxy, currentIvoRow, currentIvoColumn))
- {
- ivoStarValue += galaxy[currentIvoRow, currentIvoColumn];
- }
- currentIvoRow--;
- currentIvoColumn++;
- }
- ivoCoordinates = Console.ReadLine();
- }
- Console.WriteLine(ivoStarValue);
- }
- private static bool isInMatrix(int[,] galaxy, int givenRow, int givenColumn)
- {
- bool result = givenRow >= 0
- && givenRow < galaxy.GetLength(0)
- && givenColumn >= 0
- && givenColumn < galaxy.GetLength(1);
- return result;
- }
- private static void FillMatrix(int[,] galaxy)
- {
- int currentCount = 0;
- for (int i = 0; i < galaxy.GetLength(0); i++)
- {
- for (int j = 0; j < galaxy.GetLength(1); j++)
- {
- galaxy[i, j] = currentCount;
- currentCount++;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment