- 扫雷游戏
- 2016-10-20 22:06:46 @
有人用这种方法吗
```c++
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int m,n;
cin>>n>>m;
int A[100][100]={0};
char c;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>c;
if(c=='*'){
A[i][j]=-1;
if(i-1>=0){
if(j-1>=0&&A[i-1][j-1]>=0)
A[i-1][j-1]++;
if(A[i-1][j]>=0)
A[i-1][j]++;
if(j+1<n&&A[i-1][j+1]>=0)
A[i-1][j+1]++;
}
if(j-1>=0&&A[i][j-1]>=0)
A[i][j-1]++;
if(j+1<n&&A[i][j+1]>=0)
A[i][j+1]++;
if(i+1<n){
if(j-1>=0&&A[i+1][j-1]>=0)
A[i+1][j-1]++;
if(A[i+1][j]>=0)
A[i+1][j]++;
if(j+1<n&&A[i+1][j+1]>=0)
A[i+1][j+1]++;
}
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(A[i][j]<0){
cout<<'*';
}else{
cout<<A[i][j];
}
}
cout<<endl;
}
return 0;
}
```