555救救我呀。。。
查看原帖
555救救我呀。。。
1284590
___ikunn楼主2024/10/27 15:10
#include<bits/stdc++.h>

using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    int a[n][m],b[n][m];
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            cin >> a[i][j];
            b[i][j] = a[i][j];
        }
    }
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            if(i != 0 && i != n - 1 && j != 0 && j != m - 1){
                a[i][j] = floor((b[i + 1][j] + b[i - 1][j] + b[i][j + 1] + b[i][j - 1]) / 4 + 0.5);
            }
        }
    }
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            cout << a[i][j] << ' ';
        }
        cout << endl;
    }
    return 0;
}
2024/10/27 15:10
加载中...