Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _3._Maximal_Sum
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int[] size = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToArray();
- int rows = size[0];
- int cols = size[1];
- int[,] matrix = new int[rows, cols];
- int sum = int.MinValue;
- int rowIndex = 0;
- int colIndex = 0;
- for (int row = 0; row < rows; row++)
- {
- int[] array = Console.ReadLine()
- .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) //here
- .Select(int.Parse)
- .ToArray();
- for (int col = 0; col < cols; col++)
- {
- matrix[row, col] = array[col];
- }
- }
- for (int row = 0; row < rows - 2; row++)
- {
- for (int col = 0; col < cols - 2; col++)
- {
- int curentSum = 0;
- curentSum += matrix[row, col];
- curentSum += matrix[row, col + 1];
- curentSum += matrix[row, col + 2];
- curentSum += matrix[row + 1, col];
- curentSum += matrix[row + 1, col + 1];
- curentSum += matrix[row + 1, col + 2];
- curentSum += matrix[row + 2, col];
- curentSum += matrix[row + 2, col + 1];
- curentSum += matrix[row + 2, col + 2];
- if (curentSum > sum)
- {
- sum = curentSum;
- rowIndex = row;
- colIndex = col;
- }
- }
- }
- Console.WriteLine($"Sum = {sum}");
- for (int indexR = rowIndex; indexR < rowIndex + 3; indexR++)
- {
- for (int indexC = colIndex; indexC < colIndex + 3; indexC++)
- {
- Console.Write(matrix[indexR, indexC] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement