Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- int row, col, n;
- cin >> row >> col;
- vector<vector<int>> matrix;
- for (int i = 0; i < row; i++) {
- vector<int> currentRow;
- for (int j = 0; j < col; j++) {
- cin >> n;
- currentRow.push_back(n);
- }
- matrix.push_back(currentRow);
- }
- int maxSum = 0, r = 0, c = 0;
- for (int i = 0; i < row - 2; i++) {
- int sum = 0;
- for (int j = 0; j < col - 2; j++) {
- sum = matrix[i][j] + matrix[i][j + 1] + matrix[i][j + 2] +
- matrix[i + 1][j] + matrix[i + 1][j + 1] + matrix[i + 1][j + 2] +
- matrix[i + 2][j] + matrix[i + 2][j + 1] + matrix[i + 2][j + 2];
- if (sum > maxSum) {
- maxSum = sum;
- r = i;
- c = j;
- }
- }
- }
- cout << "Sum = " << maxSum << endl;
- for (int i = r; i < r + 3; i++) {
- for (int j = c; j < c + 3; j++) {
- cout << matrix[i][j] << ' ';
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement