Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace maximalSum
  5. {
  6. class MainClass
  7. {
  8. public static void Main(string[] args)
  9. {
  10. int[] sizes = Console.ReadLine()
  11. .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  12. .Select(int.Parse)
  13. .ToArray();
  14.  
  15. int[,] matrix = new int[sizes[0], sizes[1]];
  16.  
  17. for (int i = 0; i < matrix.GetLength(0); i++)
  18. {
  19. int[] row = Console.ReadLine()
  20. .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  21. .Select(int.Parse)
  22. .ToArray();
  23.  
  24. for (int j = 0; j < matrix.GetLength(1); j++)
  25. {
  26. matrix[i, j] = row[j];
  27. }
  28. }
  29.  
  30. int maxSum = int.MinValue;
  31. int maxRow = 0;
  32. int maxCol = 0;
  33.  
  34. for (int i = 0; i < matrix.GetLength(0) - 2; i++)
  35. {
  36. for (int j = 0; j < matrix.GetLength(1) - 2; j++)
  37. {
  38. int currentSum = 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];
  39.  
  40. if (currentSum > maxSum)
  41. {
  42. maxSum = currentSum;
  43. maxRow = i;
  44. maxCol = j;
  45. }
  46. }
  47. }
  48.  
  49. Console.WriteLine($"Sum = {maxSum}");
  50.  
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement