Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Matrix
- {
- using System;
- using System.Linq;
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Input(row, col)");
- var rowCol = Console.ReadLine()
- .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- int[][] matrix = new int[rowCol[0]][];
- int[][] maxMatrix = new int[3][];
- Console.WriteLine("Rows: "); // spaces
- for (int row = 0; row < rowCol[0]; row++)
- {
- matrix[row] = Console.ReadLine()
- .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- }
- for (int row = 0; row < 3; row++)
- {
- maxMatrix[row] = matrix[row].Take(3).ToArray();
- }
- for (int row = 0; row < rowCol[0] - 2; row++)
- {
- for (int col = 0; col < rowCol[1] - 2; col++)
- {
- if (matrix[row].Skip(col).Take(3).Sum() +
- matrix[row + 1].Skip(col).Take(3).Sum() +
- matrix[row + 2].Skip(col).Take(3).Sum()
- >
- maxMatrix[0].Sum() +
- maxMatrix[1].Sum() +
- maxMatrix[2].Sum())
- {
- maxMatrix[0] = matrix[row].Skip(col).Take(3).ToArray();
- maxMatrix[1] = matrix[row + 1].Skip(col).Take(3).ToArray();
- maxMatrix[2] = matrix[row + 2].Skip(col).Take(3).ToArray();
- }
- }
- }
- Console.WriteLine($"Sum = {maxMatrix[0].Sum() + maxMatrix[1].Sum() + maxMatrix[2].Sum()}");
- for (int row = 0; row < 3; row++)
- {
- Console.WriteLine(string.Join(" ", maxMatrix[row]));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement