Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _2.Basic_Stack_Operations
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class BasicStack
- {
- public static void Main()
- {
- var lines = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
- int rows = lines[0];
- int cols = lines[1];
- int[,] matrix = new int[rows, cols];
- for (int row = 0; row < rows; row++)
- {
- var currentRow = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- for (int col = 0; col < cols; col++)
- {
- matrix[row, col] = currentRow[col];
- }
- }
- int biggestSum = 0;
- int startrow = 0;
- int startcol = 0;
- for (int row = 0; row < rows-2; row++)
- {
- for (int col = 0; col < cols-2; col++)
- {
- int sum = 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(biggestSum<sum)
- {
- biggestSum = sum;
- startrow = row;
- startcol = col;
- }
- }
- }
- Console.WriteLine($"Sum = {biggestSum}");
- for (int i = startrow; i <= startrow + 2; i++)
- {
- for (int j = startcol; j <= startcol + 2; j++)
- {
- Console.Write("{0} ", matrix[i, j]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement