Advertisement
dsavov_02

sbor na nai golemi vuv kvadrat

Mar 1st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. public class Program
  5. {
  6. public static void Main()
  7. {
  8. int[,] matrix = {
  9.  
  10. { 0, 2, 4, 0, 9, 5 },
  11.  
  12. { 7, 1, 3, 3, 2, 1 },
  13.  
  14. { 1, 3, 9, 8, 5, 6 },
  15.  
  16. { 4, 6, 7, 9, 1, 0 }
  17.  
  18. };
  19. int bestSum = int.MinValue;
  20. int bestcol = 0;
  21. int bestrow = 0;
  22.  
  23. for(int row = 0; row < matrix.GetLength(0) - 1; row++)
  24. {
  25. for(int col = 0; col < matrix.GetLength(1) - 1; col++)
  26. {
  27. int sum = matrix[row, col] + matrix[row + 1, col] +matrix[row, col+1] + matrix[row + 1, col + 1];
  28. if (sum> bestSum)
  29. {
  30. bestSum = sum;
  31. bestrow= row;
  32. bestcol=col;
  33. }
  34. }
  35. }
  36. Console.WriteLine("The best platform is:");
  37. Console.WriteLine(" {0} {1}",matrix[bestrow, bestcol],matrix[bestrow, bestcol + 1]);
  38. Console.WriteLine(" {0} {1}", matrix[bestrow + 1, bestcol], matrix[bestrow + 1, bestcol + 1]);Console.WriteLine("The maximal sum is: {0}", bestSum);
  39. Console.WriteLine("The maximal sum is: {0}", bestSum);
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement