NadyaMisheva

bestSum bestCol bestRow

Feb 24th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 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[,] mn =
  9. {
  10. {0, 2, 4, 0, 9, 5},
  11. {7, 1, 3, 3, 2, 1},
  12. {1, 3, 9, 8, 5, 6},
  13. {4, 6, 7, 9, 1, 0},
  14. };
  15. int bestSum = int.MinValue;
  16. int bestCol = 0;
  17. int bestRow = 0;
  18. for(int row = 0; row < mn.GetLength(0) - 1 ; row++)
  19. {
  20. for(int col = 0; col < mn.GetLength(1) - 1; col++)
  21. {
  22. int sum = mn[row, col] + mn[row+1, col] + mn[row, col+1] + mn[row+1, col+1];
  23. if(sum > bestSum)
  24. {
  25. bestRow = row;
  26. bestCol = col;
  27. bestSum = sum;
  28. }
  29. }
  30. }
  31. Console.WriteLine("The best platform is:");
  32. Console.WriteLine(" {0}, {1}", mn[bestRow, bestCol], mn[bestRow, bestCol+ 1]);
  33. Console.WriteLine(" {0}, {1}", mn[bestRow + 1, bestCol], mn[bestRow + 1, bestCol + 1]);
  34. Console.WriteLine("The best sum is: {0}", bestSum);
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment