40分求助
查看原帖
40分求助
1011277
laozhang_123楼主2023/12/23 18:03
#include<bits/stdc++.h>
using namespace std;
int posx[9]={1,1,1,0,0,-1,-1,-1},posy[9]={-1,0,1,-1,-1,-1,0,1};
char g[110][110];
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++)
            cin>>g[i][j];}
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(g[i][j]=='*')
                continue;
            int cnt=0;
            for(int k=0;k<8;k++){
                if(g[i+posx[k]][j+posy[k]]=='*')
                    cnt++;}
            g[i][j]=cnt+48;}}
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++)
            cout<<g[i][j];
        cout<<endl;}
    return 0;
}

2023/12/23 18:03
加载中...