ina_abadjieva

MaxPlatform3x3

Jun 1st, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 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.  
  8. namespace MaxPlatform3x3
  9. {
  10. class MaxPlatform3x3
  11. {
  12. static void Main(string[] args)
  13. {
  14. var rowsCols = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  15. int rows = rowsCols[0];
  16. int cols = rowsCols[1];
  17. var matrix = new int[rows, cols];
  18.  
  19. //reading the matrix
  20. for (int row = 0; row < rows; row++)
  21. {
  22. var cells = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  23. for (int col = 0; col < cols; col++)
  24. {
  25. matrix[row, col] = cells[col];
  26. }
  27. }
  28.  
  29. //algorithm
  30. long maxSum = 0;
  31. var result = new int[3, 3];
  32.  
  33. for (int row = 0; row < rows - 2; row++)
  34. {
  35. for (int col = 0; col < cols - 2; col++)
  36. {
  37. long sum = 0;
  38. for (int i = 0; i < 3; i++)
  39. {
  40. for (int j = 0; j < 3; j++)
  41. {
  42. sum += matrix[row + i, col + j];
  43. }
  44. }
  45. if (sum > maxSum)
  46. {
  47. maxSum = sum;
  48. for (int i = 0; i < 3; i++)
  49. {
  50. for (int j = 0; j < 3; j++)
  51. {
  52. result[i, j] = matrix[row + i, col + j];
  53. }
  54. }
  55. }
  56. }
  57. }
  58.  
  59. Console.WriteLine(maxSum);
  60. for (int row = 0; row < 3; row++)
  61. {
  62. for (int col = 0; col < 3; col++)
  63. {
  64. Console.Write(result[row, col] + " ");
  65. }
  66. Console.WriteLine();
  67. }
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment