Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Advanced
- {
- class Program
- {
- static void Main(string[] args)
- {
- var dimentions = Console.ReadLine()
- .Split(new[] { ' '}, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- int rows = dimentions[0];
- int cols = dimentions[1];
- var matrix = new int[rows, cols];
- for (int row = 0; row < rows; row++)
- {
- var currentRow = Console.ReadLine()
- .Split(new[] { ' '}, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- for (int col = 0; col < cols; col++)
- {
- matrix[row, col] = currentRow[col];
- }
- }
- int maxSum = int.MinValue;
- int maxRowIndex = 0;
- int maxColIndex = 0;
- for (int row = 0; row < matrix.GetLength(0) - 2; row++)
- {
- for (int col = 0; col < matrix.GetLength(1) - 2; col++)
- {
- var currentSum = matrix[row, col]
- + matrix[row, col + 1]
- + matrix[row, col + 2]
- + matrix[row + 1, col]
- + matrix[row + 1, col + 1]
- + matrix[row + 1, col + 2]
- + matrix[row + 2, col]
- + matrix[row + 2, col + 1]
- + matrix[row + 2, col + 2];
- if (currentSum > maxSum)
- {
- maxSum = currentSum;
- maxRowIndex = row;
- maxColIndex = col;
- }
- }
- }
- Console.WriteLine($"Sum = {maxSum}");
- Console.WriteLine($"{matrix[maxRowIndex, maxColIndex]} {matrix[maxRowIndex, maxColIndex + 1]} {matrix[maxRowIndex, maxColIndex + 2]}");
- Console.WriteLine($"{matrix[maxRowIndex + 1, maxColIndex]} {matrix[maxRowIndex + 1, maxColIndex + 1]} {matrix[maxRowIndex + 1, maxColIndex + 2]}");
- Console.WriteLine($"{matrix[maxRowIndex + 2, maxColIndex]} {matrix[maxRowIndex + 2, maxColIndex + 1]} {matrix[maxRowIndex + 2, maxColIndex + 2]}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement