Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 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 dvumeren_masiv
  8. {
  9. class Program
  10. {
  11. static int [,] Submatrix(int[,] matrix)
  12. {
  13. int[,] res = new int[2, 2];
  14. int suma = 0;
  15. int result = 0;
  16. for (int i = 0; i < matrix.GetLength(0)-1; i+=1)
  17. {
  18. for (int j = 0; j < matrix.GetLength(1)-1; j += 1)
  19. {
  20. suma = matrix[i, j] + matrix[i + 1, j] + matrix[i, j + 1] + matrix[i + 1, j + 1];
  21. if (result < suma)
  22. {
  23. result = suma;
  24. res[0, 0] = matrix[i, j];
  25. res[0, 1] = matrix[i, j + 1];
  26. res[1, 0] = matrix[i+1, j];
  27. res[1, 1] = matrix[i+1, j+1];
  28. }
  29. }
  30. }
  31. return res;
  32. }
  33. static void Main(string[] args)
  34. {
  35. //pod matrica s maksimalna suma na elementite
  36. Console.Write("Въведи редове=");
  37. int row = int.Parse(Console.ReadLine());
  38. Console.Write("въведи колони=");
  39. int col = int.Parse(Console.ReadLine());
  40. int[,] masiv = new int[row, col];
  41. for (int i = 0; i < row; i++)
  42. {
  43. for (int j = 0; j < col; j++)
  44. {
  45. Console.Write("a[{0},{1}]=", i, j);
  46. int el = int.Parse(Console.ReadLine());
  47. masiv[i,j] = el;
  48. }
  49. }
  50. for (int i = 0; i < row; i++)
  51. {
  52. for (int j = 0; j < col; j++)
  53. {
  54. Console.Write(masiv[i, j]+" ");
  55. }
  56. Console.WriteLine();
  57. }
  58. Console.WriteLine("Подматрицата е:");
  59. int[,]matrix = Submatrix(masiv);
  60. Console.Write(matrix[0, 0]+" ");
  61. Console.WriteLine(matrix[0, 1]);
  62. Console.Write(matrix[1, 0]+" ");
  63. Console.WriteLine(matrix[1, 1]);
  64.  
  65. Console.WriteLine("Сумата на максималната подматрицата ={0}", matrix[0, 0] + matrix[0, 1] + matrix[1, 0] + matrix[1, 1]);
  66.  
  67.  
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement