Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _3._Maximal_Sum
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] sizes = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int rows = sizes[0];
- int cols = sizes[1];
- int[,] arr = new int[rows, cols];
- int[,] secondArr = new int[3, 3];
- int counter = 1;
- int sum = 0;
- List<int> finalNumbers = new List<int>();
- for (int row = 0; row < arr.GetLength(0); row++)
- {
- List<int> currentLine = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
- for (int col = 0; col < arr.GetLength(1); col++)
- {
- arr[row, col] = currentLine[col];
- }
- }
- for (int row = 0; row < arr.GetLength(0) - 2; row++)
- {
- for (int col = 0; col < arr.GetLength(1) - 2; col++)
- {
- List<int> tempNumbers = new List<int>();
- tempNumbers.Add(arr[row, col]);
- tempNumbers.Add(arr[row, col + 1]);
- tempNumbers.Add(arr[row, col + 2]);
- tempNumbers.Add(arr[row + 1, col]);
- tempNumbers.Add(arr[row + 1, col + 1]);
- tempNumbers.Add(arr[row + 1, col + 2]);
- tempNumbers.Add(arr[row + 2, col]);
- tempNumbers.Add(arr[row + 2, col + 1]);
- tempNumbers.Add(arr[row + 2, col + 2]);
- if (tempNumbers.Sum() > sum)
- {
- sum = tempNumbers.Sum();
- finalNumbers.Clear();
- for (int i = 0; i < tempNumbers.Count; i++)
- {
- finalNumbers.Add(tempNumbers[i]);
- }
- }
- }
- }
- Console.WriteLine($"Sum = {sum}");
- for (int i = 0; i < finalNumbers.Count; i++)
- {
- Console.Write(finalNumbers[i] + " ");
- if (counter % 3 == 0)
- {
- Console.WriteLine();
- }
- counter++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement