Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _2x2
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] dimentions = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
- int rows = dimentions[0];
- int cols = dimentions[1];
- int[,] matrix = new int[rows, cols];
- Initialized(matrix);
- int maxSum = int.MinValue;
- int targetRow = 0;
- int targetCol = 0;
- for (int row = 0; row < matrix.GetLength(0) - 2; row++)
- {
- for (int col = 0; col < matrix.GetLength(1) - 2; col++)
- {
- int 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(maxSum < currentSum)
- {
- maxSum = currentSum;
- targetRow = row;
- targetCol = col;
- }
- }
- }
- Console.WriteLine($"Sum = {maxSum}");
- for (int row = targetRow; row <= targetRow + 2; row++)
- {
- for (int col = targetCol; col <= targetCol + 2; col++)
- {
- Console.Write(matrix[row,col] + " ");
- }
- Console.WriteLine();
- }
- }
- private static void Initialized(int[,] matrix)
- {
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- int[] rowAsChar = Console.ReadLine().Split(" ",StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- matrix[row, col] = rowAsChar[col];
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement