Advertisement
Guest User

Untitled

a guest
Sep 18th, 2016
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class Program
  5. {
  6. static void Main()
  7. {
  8. int sumTop = 0;
  9. int sumBot = 0;
  10. int sumSums = 0;
  11. int maxHourGlass = int.MinValue;
  12.  
  13. int[][] matrix = new int[6][];
  14.  
  15. //Read the matrix
  16. byte rows = 6;
  17. byte cols = 6;
  18. for (byte i = 0; i < rows; i++)
  19. {
  20. matrix[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
  21. }
  22.  
  23. //Scan the matrix's hourglasses and sum:
  24. for (byte i = 1; i < rows - 1; i++)
  25. {
  26. for (byte j = 1; j < cols - 1; j++)
  27. {
  28. sumTop = matrix[i - 1][j - 1] + matrix[i - 1][j] + matrix[i - 1][j + 1];
  29. sumBot = matrix[i + 1][j - 1] + matrix[i + 1][j] + matrix[i + 1][j + 1];
  30. sumSums = sumTop + matrix[i][j] + sumBot;
  31.  
  32. if (sumSums > maxHourGlass)
  33. {
  34. maxHourGlass = sumSums;
  35. }
  36. }
  37. }
  38. Console.WriteLine(maxHourGlass);
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement