Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MaxPlatform2x2
- {
- class bestSumBestRowBestColl
- {
- static void Main(string[] args)
- {
- string[] rowsColls = Console.ReadLine().Split(' ');
- int[] rowsCollsInt = rowsColls.Select(int.Parse).ToArray();
- int[,] matrix = new int[rowsCollsInt[0], rowsCollsInt[1]];
- for (int i = 0; i < rowsCollsInt[0]; i++)
- {
- string[] input = Console.ReadLine().Split(' ');
- for (int j = 0; j < rowsCollsInt[1]; j++)
- {
- matrix[i, j] = int.Parse(input[j]);
- }
- }
- int bestSum = int.MinValue;
- int bestRow = 0;
- int bestColl = 0;
- for (int i = 0; i < matrix.GetLength(0) - 2; i++)
- {
- for (int j = 0; j < matrix.GetLength(1) - 2; j++)
- {
- int sum = matrix[i, j] + matrix[i, j + 1] + matrix[i, j + 2] + matrix[i + 1, j] + matrix[i + 1, j + 1] + matrix[i + 1, j + 2] + matrix[i + 2, j] + matrix[i + 2, j + 1] + matrix[i + 2, j + 2];
- if (sum > bestSum)
- bestSum = sum;
- {
- bestRow = i;
- bestColl = j;
- }
- }
- }
- Console.WriteLine("best matc:");
- Console.WriteLine("{0} {1} {2}", matrix[bestRow, bestColl - 1], matrix[bestRow, bestColl], matrix[bestRow, bestColl + 1]);
- Console.WriteLine("{0} {1} {2}", matrix[bestRow + 1, bestColl - 1], matrix[bestRow + 1, bestColl], matrix[bestRow + 1, bestColl + 1]);
- Console.WriteLine("{0} {1} {2}", matrix[bestRow + 2, bestColl - 1], matrix[bestRow + 2, bestColl], matrix[bestRow + 2, bestColl + 1]);
- Console.WriteLine("Sum = {0}", bestSum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement