NedyalkoKikov

MaxPlatform3X3

Jun 10th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace MaxPlatform3_3
  8. {
  9. class Program
  10. {
  11. static void Main()
  12. {
  13. int[] dimennsions = Console.ReadLine().Split().Select(int.Parse).ToArray();
  14. int rows = dimennsions[0];
  15. int cols = dimennsions[1];
  16. int[][] matrix = new int[rows][];
  17. for (int row = 0; row < rows; row++)
  18. {
  19. matrix[row] = Console.ReadLine().Split().Select(int.Parse).ToArray();
  20. }
  21. long maximumSum = int.MinValue;
  22. int maxRow = 0;
  23. int maxCol = 0;
  24. for (int row = 0; row < rows-2; row++)
  25. {
  26. for (int col = 0; col < cols - 2; col++)
  27. {
  28. //ckeck cells
  29. long sum = (long)matrix[row][col] + matrix[row][col + 1] + matrix[row][col + 2] +
  30. matrix[row + 1][col] + matrix[row + 1][col + 1] + matrix[row + 1][col + 2] +
  31. matrix[row + 2][col] + matrix[row + 2][col + 1] + matrix[row + 2][col + 2];
  32. if(sum > maximumSum)
  33. {
  34. maximumSum = sum;
  35. maxRow = row;
  36. maxCol = col;
  37. }
  38. }
  39.  
  40. }
  41. Console.WriteLine(maximumSum);
  42. for (int row = maxRow; row < maxRow+3; row++)
  43. {
  44. for (int col = maxCol; col < maxCol+3; col++)
  45. {
  46. Console.Write(matrix[row][col] + " ");
  47. }
  48. Console.WriteLine();
  49. }
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment