WA #4 #5 #6 #7 #9 #10 求助~
查看原帖
WA #4 #5 #6 #7 #9 #10 求助~
719201
INT_1024楼主2022/12/14 16:12
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    char cnt[a][b];
    int t=0;
    for(int i=0;i<a;i++)
    	for(int j=0;j<b;j++)
    		cin>>cnt[i][j];
    for(int i=0;i<a;i++)
    {
    	for(int j=0;j<b;j++)
    	{
    		t=0;
    		if(cnt[i][j]=='*')
    			cout<<"*";
    		else if(cnt[i][j]=='?')
    		{
    			for(int k=i-1;k<=i+1;k++)
    				for(int l=j-1;l<=j+1;l++)
    					if(!(k<0 || l<0))
    						if(cnt[k][l]=='*')
    							t++;
				cout<<t;
			}
		}
		cout<<endl;
	}
    return 0;
}

想法是遍历周围8个点,寻找是否有地雷,有则++

2022/12/14 16:12
加载中...