Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- class Program
- {
- static void Main()
- {
- int sumTop = 0;
- int sumBot = 0;
- int sumSums = 0;
- int maxHourGlass = int.MinValue;
- int[][] matrix = new int[6][];
- //Read the matrix
- byte rows = 6;
- byte cols = 6;
- for (byte i = 0; i < rows; i++)
- {
- matrix[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
- }
- //Scan the matrix's hourglasses and sum:
- for (byte i = 1; i < rows - 1; i++)
- {
- for (byte j = 1; j < cols - 1; j++)
- {
- sumTop = matrix[i - 1][j - 1] + matrix[i - 1][j] + matrix[i - 1][j + 1];
- sumBot = matrix[i + 1][j - 1] + matrix[i + 1][j] + matrix[i + 1][j + 1];
- sumSums = sumTop + matrix[i][j] + sumBot;
- if (sumSums > maxHourGlass)
- {
- maxHourGlass = sumSums;
- }
- }
- }
- Console.WriteLine(maxHourGlass);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement