P2670扫雷

链接

题解:(其实还是循环阿)

#include<iostream>
#include<cstdio>
using namespace std;
int m,n;
char a[101][101];//雷
int b[101][101];//周围有几颗雷
bool c[101][101];
void print()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{if(a[i][j]=='*')cout<<a[i][j];
else cout<<b[i][j];
if(j==m)cout<<endl;
}
}
}
void search(int x,int y)
{ for(int i=x;i<=n;i++)
{
for(int j=y;j<=m;j++)
{if(a[i][j]=='*')
{b[i][j+1]++;b[i-1][j]++;b[i+1][j]++;b[i][j-1]++;
b[i-1][j-1]++;b[i-1][j+1]++;b[i+1][j+1]++;b[i+1][j-1]++;}
}
}
print();
}

int main()
{cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
cin>>a[i][j];
}
search(1,1);
}

猜你喜欢

转载自www.cnblogs.com/lcez56jsy/p/10403466.html