Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class MaximalSumOfMandN
- {
- static void Main()
- {
- int n, m, count = int.MinValue, maxCount = int.MinValue, one = 0, two = 0, three = 0, four = 0, five = 0, six = 0, seven = 0, eight = 0, nine = 0;
- n = int.Parse(Console.ReadLine());
- if (n < 3)
- {
- Console.WriteLine("The N value must be at least equal to 3!");
- }
- m = int.Parse(Console.ReadLine());
- if (n < 3)
- {
- Console.WriteLine("The M value must be at least equal to 3!");
- }
- int[,] myMatrix = new int[n,m];
- for (int row = 0; row < n; row++)
- {
- for (int col = 0; col < m; col++)
- {
- myMatrix[row, col] = int.Parse(Console.ReadLine());
- }
- }
- for (int rowA = 0, rowB = 1, rowC = 2; rowC < n; rowA++, rowB++, rowC++)
- {
- for (int colA = 0, colB = 1, colC = 2; colC < m; colA++, colB++, colC++)
- {
- count = myMatrix[rowA, colA] + myMatrix[rowA, colB] + myMatrix[rowA, colC] + myMatrix[rowB, colA] + myMatrix[rowB, colB] + myMatrix[rowB, colC]
- + myMatrix[rowC, colA] + myMatrix[rowC, colB] + myMatrix[rowC, colC];
- if (count > maxCount)
- {
- maxCount = count;
- one = myMatrix[rowA, colA];
- two = myMatrix[rowA, colB];
- three = myMatrix[rowA, colC];
- four = myMatrix[rowB, colA];
- five = myMatrix[rowB, colB];
- six = myMatrix[rowB, colC];
- seven = myMatrix[rowC, colA];
- eight = myMatrix[rowC, colB];
- nine = myMatrix[rowC, colC];
- }
- else
- {
- continue;
- }
- }
- }
- for (int row = 0; row < n; row++)
- {
- for (int col = 0; col < m; col++)
- {
- Console.Write(myMatrix[row, col] + " ");
- }
- Console.WriteLine();
- }
- Console.WriteLine("\n\r\n\r");
- Console.WriteLine("{0}, {1}, {2} \n\r{3}, {4}, {5} \n\r{6}, {7}, {8} \n\r\n\rMax sum = {9}", one, two, three, four, five, six, seven, eight, nine, maxCount);
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement