Advertisement
Guest User

Untitled

a guest
Jul 4th, 2020
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace MaximalSum
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int[] N = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  12.  
  13. int[,] matrix = new int[N[0], N[1]];
  14. string[,] submatrix = new string[3, 3];
  15. int sum = 0;
  16. int[] maxSum = new int[N[0]];
  17. Dictionary<int, string[,]> myDict = new Dictionary<int, string[,]>();
  18.  
  19. for (int rows = 0; rows < N[0]; rows++)
  20. {
  21. int[] numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  22.  
  23. for (int cols = 0; cols < N[1]; cols++)
  24. {
  25. matrix[rows, cols] = numbers[cols];
  26. }
  27. }
  28. for (int rows = 0; rows < N[0] - 2; rows++)
  29. {
  30. for (int cols = 0; cols < N[1] - 3; cols++)
  31. {
  32.  
  33. sum = matrix[rows, cols] + matrix[rows, cols + 1] + matrix[rows, cols + 2] + matrix[rows + 1, cols] + matrix[rows + 1, cols + 1] + matrix[rows + 1, cols + 2] + matrix[rows + 2, cols] + matrix[rows + 2, cols + 1] + matrix[rows + 2, cols + 2];
  34.  
  35. submatrix[rows, cols] = matrix[rows, cols] +" "+ matrix[rows, cols + 1] +" "+ matrix[rows, cols + 2] +" "+ matrix[rows + 1, cols] +" "+ matrix[rows + 1, cols + 1] +" "+ matrix[rows + 1, cols + 2] +" "+ matrix[rows + 2, cols] +" "+ matrix[rows + 2, cols + 1] +" "+ matrix[rows + 2, cols + 2];
  36.  
  37. myDict.Add(sum, submatrix);
  38. maxSum[cols] = sum;
  39. }
  40. }
  41. Console.WriteLine(maxSum.Max());
  42.  
  43. string[,] result = new string[3, 3];
  44. myDict.TryGetValue(maxSum.Max(), out submatrix);
  45.  
  46.  
  47. Console.WriteLine(submatrix);
  48.  
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement