Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1.  
  2. namespace _2.Basic_Stack_Operations
  3. {
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7.  
  8. public class BasicStack
  9. {
  10. public static void Main()
  11. {
  12. var lines = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  13. int rows = lines[0];
  14. int cols = lines[1];
  15. int[,] matrix = new int[rows, cols];
  16. for (int row = 0; row < rows; row++)
  17. {
  18. var currentRow = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  19. for (int col = 0; col < cols; col++)
  20. {
  21. matrix[row, col] = currentRow[col];
  22. }
  23. }
  24. int biggestSum = 0;
  25. int startrow = 0;
  26. int startcol = 0;
  27. for (int row = 0; row < rows-2; row++)
  28. {
  29. for (int col = 0; col < cols-2; col++)
  30. {
  31. int sum = matrix[row, col]
  32. + matrix[row, col + 1]
  33. + matrix[row, col + 2]
  34. + matrix[row + 1, col]
  35. + matrix[row + 1, col + 1]
  36. + matrix[row + 1, col + 2]
  37. + matrix[row + 2, col]
  38. + matrix[row + 2, col + 1]
  39. + matrix[row + 2, col + 2];
  40. if(biggestSum<sum)
  41. {
  42. biggestSum = sum;
  43. startrow = row;
  44. startcol = col;
  45. }
  46. }
  47. }
  48. Console.WriteLine($"Sum = {biggestSum}");
  49.  
  50. for (int i = startrow; i <= startrow + 2; i++)
  51. {
  52. for (int j = startcol; j <= startcol + 2; j++)
  53. {
  54. Console.Write("{0} ", matrix[i, j]);
  55. }
  56. Console.WriteLine();
  57. }
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement