include iostream include stdio using namespace std int размерность мат

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <stdio.h>
using namespace std;
int n, m; //размерность матрицы
int matrix[10][12];
void ReadMatrix() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> matrix[i][j];
}
}
}
int CalcScore(int i, int j) {
int score = 0;
if (i > 0) score += matrix[i - 1][j];
if (i + 1 < n) score += matrix[i + 1][j];
if (j > 0) score += matrix[i][j - 1];
if (j + 1 < m) score += matrix[i][j + 1];
return score;
}
int main() {
cin >> n >> m;
ReadMatrix();
int max_i = 0, max_j = 0, max = CalcScore(max_i, max_j);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (CalcScore(i, j) > max) {
max_i = i;
max_j = j;
max = CalcScore(i, j);
}
}
}
cout << "matrix[" << max_i << "][" << max_j << "] = " << max << endl;
return 0;
}