Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Jedi_Galaxy
- {
- public class StartUp
- {
- public static void Main(string[] args)
- {
- var dimensions = Console.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse).ToArray();
- var galaxy = CreateGalaxy(dimensions);
- var input = Console.ReadLine();
- var collectedStars = 0L;
- while (!input.Equals("Let the Force be with you"))
- {
- var coordinatesIvo = input.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse).ToArray();
- input = Console.ReadLine();
- var coordinatesEvil = input.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse).ToArray();
- DestroyStars(galaxy, coordinatesEvil);
- collectedStars += CollectStars(galaxy, coordinatesIvo);
- input = Console.ReadLine();
- }
- Console.WriteLine(collectedStars);
- }
- private static long CollectStars(int[][] galaxy, int[] coordinatesIvo)
- {
- var collected = 0L;
- var ivoRow = coordinatesIvo[0];
- var ivoCol = coordinatesIvo[1];
- for (int i = ivoRow, j = ivoCol; i >= 0 && j < galaxy[0].Length; i--, j++)
- {
- if (i < galaxy.Length && j >= 0)
- {
- collected += galaxy[i][j];
- }
- }
- return collected;
- }
- private static void DestroyStars(int[][] galaxy, int[] coordinates)
- {
- var evilStartRow = coordinates[0];
- var evilStartCol = coordinates[1];
- for (int i = evilStartRow, j = evilStartCol; i >= 0 && j >= 0; i--, j--)
- {
- if (i < galaxy.Length && j < galaxy[0].Length)
- {
- galaxy[i][j] = 0;
- }
- }
- }
- private static int[][] CreateGalaxy(int[] dimensions)
- {
- var row = dimensions[0];
- var col = dimensions[1];
- var matrix = new int[row][];
- for (var i = 0; i < row; i++)
- {
- matrix[i] = new int[col];
- for (var j = 0; j < col; j++)
- {
- matrix[i][j] = i * col + j;
- }
- }
- return matrix;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement