Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- public class Colecting
- {
- static void Main()
- {
- string galaxyData = Console.ReadLine();
- int[] dimestions = galaxyData
- .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- int row = dimestions[0];
- int col = dimestions[1];
- Space galaxy = new Space(dimestions[0], dimestions[1]);
- Console.WriteLine(ColectingHearths(galaxy));
- }
- private static string ColectingHearths(Space galaxy)
- {
- string loverData;
- long sum = 0L;
- Coordinates coordinates = new Coordinates();
- Evil evil = new Evil();
- Lover ivo = new Lover(sum);
- while ((loverData = Console.ReadLine()) != "Let the Force be with you")
- {
- evil = new Evil(new Coordinates(Console.ReadLine()));
- evil.RemoveStars(galaxy.Matrix);
- ivo = new Lover(new Coordinates(loverData));
- ivo.ColectingStars(galaxy.Matrix, ivo.StarsColected);
- }
- return ivo.StarsColected.ToString();
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Text;
- public class Space
- {
- int[,] matrix;
- public int[,] Matrix { get => matrix; set => matrix = value; }
- public Space(int rowCount, int colCount)
- {
- int value = 0;
- matrix = new int[rowCount, colCount];
- for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
- {
- for (int colIndex = 0; colIndex < colCount; colIndex++)
- {
- matrix[rowIndex, colIndex] = value++;
- }
- }
- Matrix = matrix;
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Text;
- public class Evil
- {
- Coordinates location;
- Coordinates Location { get => location; set => location = value; }
- public Evil()
- {
- Location = location;
- }
- public Evil(Coordinates loc)
- {
- Location = loc;
- }
- public int[,] RemoveStars(int [,] matrix)
- {
- while (Location.Row >= 0 && Location.Col >= 0)
- {
- if (Location.Row >= 0 && Location.Row < matrix.GetLength(0) && Location.Col >= 0 && Location.Col < matrix.GetLength(1))
- {
- matrix[Location.Row, Location.Col] = 0;
- }
- Location.Row--;
- Location.Col--;
- }
- return matrix;
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- public class Coordinates
- {
- int row;
- int col;
- public int Row { get => row; set => row = value; }
- public int Col { get => col; set => col = value; }
- public Coordinates()
- {
- Row = row;
- Col = col;
- }
- public Coordinates(string input)
- {
- int[] evilLocation = input
- .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse).ToArray();
- Row = evilLocation[0];
- Col = evilLocation[1];
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Text;
- public class Lover
- {
- Coordinates location;
- long starsColected;
- public long StarsColected { get => starsColected; set => starsColected = value; }
- internal Coordinates Location { get => location; set => location = value; }
- public Lover(long stars)
- {
- Location = location;
- StarsColected = stars;
- }
- public Lover(Coordinates loc)
- {
- Location = loc;
- }
- public void ColectingStars(int [,] matrix, long sum)
- {
- while (Location.Row >= 0 && Location.Col < matrix.GetLength(1))
- {
- if (Location.Row >= 0 && Location.Row < matrix.GetLength(0) && Location.Col >= 0 && Location.Col < matrix.GetLength(1))
- {
- sum += matrix[Location.Row, Location.Col];
- }
- Location.Col++;
- Location.Row--;
- }
- StarsColected = sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement