已通过,求大佬给更优解
查看原帖
已通过,求大佬给更优解
1012021
w_moon楼主2024/4/16 20:41
#include<bits/stdc++.h>
using namespace std;

int n,m,t=0;
char a[110][110];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++) {
    	for(int j=1;j<=m;j++) {
    		cin>>a[i][j];
		}
	}
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j]=='*') {
            	cout<<"*";
			} else {
                if(a[i-1][j+1]=='*') t++;
                if(a[i-1][j-1]=='*') t++;
                if(a[i-1][j]=='*') t++;
                if(a[i+1][j+1]=='*') t++;
                if(a[i+1][j-1]=='*') t++;
                if(a[i+1][j]=='*') t++;
                if(a[i][j+1]=='*') t++;
                if(a[i][j-1]=='*') t++;
                cout<<t;
                t=0;
            }          
        }
        cout<<endl;
    }
    return 0;
}
2024/4/16 20:41
加载中...